# How to Install the PHP License Key Generator Library (SunLicense)

> Install the PHP License Key Generator library easily. This drop-in solution requires PHP 5.5+ and has no external dependencies. Get started generating license keys today.

- Repository: [Mehmet Selcuk Batal/php-license-key-generator](https://github.com/msbatal/php-license-key-generator)
- Tags: getting-started
- Published: 2026-03-07

---

**The PHP License Key Generator (SunLicense) installs via a single file drop-in that requires only PHP 5.5+ and no external dependencies.**

The `msbatal/php-license-key-generator` repository provides a lightweight, self-contained solution for creating formatted license keys in PHP. Since the library consists of a single class file without external dependencies, you can install the PHP License Key Generator library by simply including it in your project. This guide walks through the exact steps to download, require, and instantiate the SunLicense class based on the source code implementation.

## Installation Steps for the PHP License Key Generator

### Download the SunLicense.php Class File

The library ships as a single class definition located in [`SunLicense.php`](https://github.com/msbatal/php-license-key-generator/blob/main/SunLicense.php) at the repository root. Download or clone the `msbatal/php-license-key-generator` repository and place this file anywhere within your project's include path. The class requires no additional vendor folders or autoloaders, making it ideal for legacy projects or minimal PHP environments.

### Require the Class in Your Project

Load the class using PHP's native `require_once` statement or your preferred autoloader. The repository's [`README.md`](https://github.com/msbatal/php-license-key-generator/blob/main/README.md) explicitly documents this requirement:

```php
require_once 'SunLicense.php';

```

Place this line at the top of any script that needs to generate license keys. If you place [`SunLicense.php`](https://github.com/msbatal/php-license-key-generator/blob/main/SunLicense.php) in a subdirectory (such as `lib/` or `vendor/`), adjust the path accordingly (e.g., `require_once 'lib/SunLicense.php'`).

### Instantiate the Generator

Create a new instance of the `SunLicense` class to begin generating keys. The constructor accepts four optional parameters that control output formatting and quantity:

- **`$prefix`** – String prepended to every key (e.g., `SLK-`)
- **`$template`** – Pattern using `A` for letters, `9` for digits, and `-` for separators
- **`$case`** – Either `'upper'` (default) or `'lower'` for alphabetic characters
- **`$count`** – Integer specifying how many unique keys to generate (defaults to `1`)

Internally, the constructor stores these values in private properties (`$prefix`, `$template`, `$case`, `$keyCount`) at lines 56–72 of [`SunLicense.php`](https://github.com/msbatal/php-license-key-generator/blob/main/SunLicense.php), applying sensible defaults when arguments are omitted.

## Understanding the SunLicense Constructor Parameters

The `SunLicense` class flexibility comes from its template-driven generation system. When you install the PHP License Key Generator library and instantiate the class, you can customize:

**Template Characters:**
- `A` generates a random alphabetic character
- `9` generates a random numeric digit
- `-` or other literals pass through unchanged

**Case Sensitivity:**
Pass `'lower'` as the third constructor argument to output lowercase letters instead of the default uppercase.

**Batch Generation:**
Set the fourth parameter to any integer greater than `1` to receive an array of unique keys rather than a single string.

## Code Examples: Installing and Using SunLicense

### Basic Single-Key Generation

This minimal example shows the default configuration after you install the PHP License Key Generator library:

```php
require_once 'SunLicense.php';

$license = new SunLicense();          // default settings: no prefix, template "AAAA-AAAA-AAAA-AAAA", upper case, count 1
echo $license->generate();           // prints a single license key like "X7K9-P2M5-V8N3-Q4W6"

```

### Custom Configuration with Multiple Keys

Generate five keys with a custom prefix, specific template, and lowercase letters:

```php
require_once 'SunLicense.php';

// prefix = "SLK", template = "AA99-9A9A-A9A9-99AA", case = lower, generate 5 keys
$license = new SunLicense('SLK', 'AA99-9A9A-A9A9-99AA', 'lower', 5);
$keys = $license->generate();        // returns an array of 5 unique keys

foreach ($keys as $key) {
    echo $key . PHP_EOL;
}

```

### Generating Batches Using Defaults

To generate multiple keys while keeping default formatting, pass `null` for unused parameters:

```php
require_once 'SunLicense.php';

// No prefix/template/case, just 3 keys
$license = new SunLicense(null, null, null, 3);
$keys = $license->generate();        // array with 3 keys using default template
print_r($keys);

```

## Key Files in the Repository

Understanding the file structure helps verify your installation:

- **[`SunLicense.php`](https://github.com/msbatal/php-license-key-generator/blob/main/SunLicense.php)** – Core class implementing key generation, uniqueness checking via the private `check()` method, and the public `generate()` entry point (lines 21–133).
- **[`README.md`](https://github.com/msbatal/php-license-key-generator/blob/main/README.md)** – Official installation guide and parameter reference.
- **[`test/index.php`](https://github.com/msbatal/php-license-key-generator/blob/main/test/index.php)** – Optional verification script demonstrating basic usage.
- **[`test/SunLicense.php`](https://github.com/msbatal/php-license-key-generator/blob/main/test/SunLicense.php)** – Extended test cases showing various constructor configurations.

## Summary

- **Single-file installation**: Copy [`SunLicense.php`](https://github.com/msbatal/php-license-key-generator/blob/main/SunLicense.php) from the `msbatal/php-license-key-generator` repository to your project.
- **Zero dependencies**: Requires only PHP 5.5+; no Composer or external libraries needed.
- **Simple inclusion**: Use `require_once 'SunLicense.php'` to load the class.
- **Flexible instantiation**: Configure via four optional constructor parameters controlling prefix, template pattern, letter case, and key count.
- **Internal validation**: The `license()` and `check()` methods ensure uniqueness before returning results via `generate()`.

## Frequently Asked Questions

### Does the PHP License Key Generator require Composer?

No. According to the source code in [`SunLicense.php`](https://github.com/msbatal/php-license-key-generator/blob/main/SunLicense.php), the library is a single self-contained class with no external dependencies. You can install it by directly downloading the file and using `require_once`, bypassing Composer entirely.

### What PHP version is required for SunLicense?

The library requires PHP 5.5 or higher. This is the only system requirement; there are no extensions or additional runtime dependencies needed to install the PHP License Key Generator library.

### How does SunLicense ensure unique keys?

The class maintains a private `$keys` array property. When generating multiple keys, the private `check()` method compares each newly generated candidate against this array. If a duplicate is detected, the `license()` method regenerates that segment until uniqueness is confirmed before the public `generate()` method returns the final set.

### Can I customize the license key format?

Yes. Pass a custom template string as the second constructor argument using `A` for alphabetic characters, `9` for digits, and literal characters like `-` for separators. For example, `AA99-9999` produces keys like "XP47-8291". Combine this with the prefix and case parameters to match your specific formatting requirements.