Official CodeIgniter 4 SDK for License Management Platform. Easy license validation, activation, and management for CodeIgniter applications with library support and helper functions.
- π Easy Integration - Simple library and helper functions
- π¨ CodeIgniter-Native - Follows CodeIgniter 4 conventions
- π οΈ Helper Functions - Convenient global functions
- π Full Logging - Optional CodeIgniter logging integration
- β‘ Response Caching - Automatic caching support
- π CodeIgniter 4.x - Full compatibility
- β¨ NEW: State-Based Validation - Enterprise-grade state management
- π‘οΈ NEW: Grace Period Support - 72-hour failover protection
- π NEW: Enhanced Security - RSA-4096 signature verification
- π NEW: API Response Codes - Standardized error handling
The CodeIgniter SDK has been hardened with enterprise-grade features:
Instead of raw API responses, use typed LicenseState objects:
helper('getkeymanager');
$state = resolve_license_state($key);
if ($state->isActive()) {
// License is fully active
} elseif ($state->isInGracePeriod()) {
// Grace period - network issues
} else {
// Invalid
}Automatic 72-hour grace period when API is unreachable:
- Prevents service disruption from network issues
- Cached licenses remain valid temporarily
- Configurable duration
use GetKeyManager\CodeIgniter\Core\ApiResponseCode;
use GetKeyManager\CodeIgniter\Core\LicenseException;
try {
$state = resolve_license_state($key);
} catch (LicenseException $e) {
$code = $e->getApiCode();
$name = $e->getApiCodeName();
$message = ApiResponseCode::getMessage($code);
}// Check license status
is_license_active($key);
is_license_in_grace_period($key);
// Feature checking
can_use_feature($key, 'premium_reports');
// State management
$state = get_license_state($key); // Get cached state
clear_license_state($key); // Clear cacheπ See HARDENING_COMPLETE.md for full documentation
β 100% Backward Compatible - All existing code continues to work!
- PHP 7.4 or higher
- CodeIgniter 4.0 or higher
- ext-json, ext-openssl, ext-curl
Install via Composer:
composer require getkeymanager/codeigniter-sdkCopy the configuration file to your app/Config directory:
cp vendor/getkeymanager/codeigniter-sdk/src/Config/GetKeyManager.php app/Config/Edit app/Config/GetKeyManager.php:
<?php
namespace Config;
use GetKeyManager\CodeIgniter\Config\GetKeyManager as BaseGetKeyManager;
class GetKeyManager extends BaseGetKeyManager
{
public string $apiKey = 'your-api-key-here';
public string $baseUrl = 'https://api.getkeymanager.com';
public string $environment = 'production';
public bool $verifySignatures = true;
public ?string $publicKey = '-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----';
// ... other settings
}You can also use .env file:
LICENSE_MANAGER_API_KEY=your-api-key-here
LICENSE_MANAGER_BASE_URL=https://api.getkeymanager.com
LICENSE_MANAGER_ENVIRONMENT=production
LICENSE_MANAGER_VERIFY_SIGNATURES=true
LICENSE_MANAGER_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----"And load them in config:
public string $apiKey;
public function __construct()
{
parent::__construct();
$this->apiKey = getenv('LICENSE_MANAGER_API_KEY');
}<?php
namespace App\Controllers;
use GetKeyManager\CodeIgniter\Libraries\GetKeyManagerLibrary;
class License extends BaseController
{
private GetKeyManagerLibrary $getkeymanager;
public function __construct()
{
$this->getkeymanager = new GetKeyManagerLibrary();
}
public function validate()
{
$licenseKey = $this->request->getPost('license_key');
$result = $this->getkeymanager->validateLicense($licenseKey, [
'hardwareId' => $this->getkeymanager->generateHardwareId()
]);
if ($result['success']) {
return $this->response->setJSON([
'status' => 'valid',
'data' => $result['data']
]);
} else {
return $this->response->setJSON([
'status' => 'invalid',
'message' => $result['message']
], 400);
}
}
}<?php
namespace App\Controllers;
class Dashboard extends BaseController
{
public function index()
{
// Load the helper
helper('getkeymanager');
$licenseKey = session()->get('license_key');
// Simple validation check
if (!is_license_valid($licenseKey)) {
return redirect()->to('/license-required');
}
// Check feature
if (is_feature_enabled($licenseKey, 'advanced-reports')) {
$data['show_advanced_reports'] = true;
}
// Get full details
$licenseDetails = get_license_details($licenseKey);
$data['license'] = $licenseDetails['data'] ?? [];
return view('dashboard', $data);
}
}use GetKeyManager\CodeIgniter\Libraries\GetKeyManagerLibrary;
$license = new GetKeyManagerLibrary();
// Validate license
$result = $license->validateLicense('XXXXX-XXXXX-XXXXX-XXXXX');
// Activate license
$result = $license->activateLicense('XXXXX-XXXXX-XXXXX-XXXXX', [
'hardwareId' => $license->generateHardwareId(),
'name' => 'Production Server'
]);
// Deactivate license
$result = $license->deactivateLicense('XXXXX-XXXXX-XXXXX-XXXXX', [
'hardwareId' => $license->generateHardwareId()
]);
// Check feature
$result = $license->checkFeature('XXXXX-XXXXX-XXXXX-XXXXX', 'premium-features');// Read offline license file
$offlineLicense = file_get_contents(WRITEPATH . 'licenses/offline.lic');
$result = $license->validateOfflineLicense($offlineLicense, [
'hardwareId' => $license->generateHardwareId()
]);$result = $license->createLicenseKeys(
'product-uuid',
'generator-uuid',
[
['activation_limit' => 5, 'validity_days' => 365],
['activation_limit' => 1, 'validity_days' => 30]
],
'customer@example.com'
);
foreach ($result['data']['licenses'] as $lic) {
echo "Created: " . $lic['license_key'] . "\n";
}Load the helper in your controller or view:
helper('getkeymanager');Get the library instance.
$license = getkeymanager();Validate a license key.
$result = validate_license('XXXXX-XXXXX-XXXXX-XXXXX', [
'hardwareId' => generate_hardware_id()
]);Quick boolean check if license is valid.
if (is_license_valid($licenseKey)) {
// License is valid
}Activate a license.
$result = activate_license('XXXXX-XXXXX-XXXXX-XXXXX', [
'hardwareId' => generate_hardware_id()
]);Deactivate a license.
$result = deactivate_license('XXXXX-XXXXX-XXXXX-XXXXX', [
'hardwareId' => generate_hardware_id()
]);Check if a feature is enabled.
$result = check_feature('XXXXX-XXXXX-XXXXX-XXXXX', 'api-access');Quick boolean check if feature is enabled.
if (is_feature_enabled($licenseKey, 'exports')) {
// Show export button
}Get detailed license information.
$details = get_license_details('XXXXX-XXXXX-XXXXX-XXXXX');Generate a hardware ID for this device.
$hwid = generate_hardware_id();Generate a UUID v4.
$uuid = generate_uuid();Validate an offline license file.
$offlineData = file_get_contents('license.lic');
$result = validate_offline_license($offlineData);Create a filter for route protection:
<?php
namespace App\Filters;
use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
class LicenseFilter implements FilterInterface
{
public function before(RequestInterface $request, $arguments = null)
{
helper('getkeymanager');
$licenseKey = session()->get('license_key');
if (!$licenseKey || !is_license_valid($licenseKey)) {
return redirect()->to('/license-required')
->with('error', 'Valid license required');
}
// Check specific feature if provided
if ($arguments && is_feature_enabled($licenseKey, $arguments[0]) === false) {
return redirect()->to('/upgrade-required')
->with('error', 'This feature requires an upgrade');
}
}
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{
// Do nothing
}
}Register in app/Config/Filters.php:
public array $aliases = [
'license' => \App\Filters\LicenseFilter::class,
];Use in routes:
$routes->group('dashboard', ['filter' => 'license'], function($routes) {
$routes->get('/', 'Dashboard::index');
$routes->get('reports', 'Dashboard::reports', ['filter' => 'license:advanced-reports']);
});use GetKeyManager\CodeIgniter\Libraries\GetKeyManagerLibrary;
$license = new GetKeyManagerLibrary();
// Get license details
$details = $license->getLicenseDetails('XXXXX-XXXXX-XXXXX-XXXXX');
// Get activations
$activations = $license->getLicenseActivations('XXXXX-XXXXX-XXXXX-XXXXX');
// Suspend license
$license->suspendLicense('XXXXX-XXXXX-XXXXX-XXXXX');
// Resume license
$license->resumeLicense('XXXXX-XXXXX-XXXXX-XXXXX');
// Revoke license (permanent)
$license->revokeLicense('XXXXX-XXXXX-XXXXX-XXXXX');// Update metadata
$license->updateLicenseMetadata('XXXXX-XXXXX-XXXXX-XXXXX', [
'server_name' => 'prod-01',
'deployed_at' => date('Y-m-d H:i:s')
]);
// Get metadata
$metadata = $license->getLicenseMetadata('XXXXX-XXXXX-XXXXX-XXXXX');
// Delete metadata key
$license->deleteLicenseMetadata('XXXXX-XXXXX-XXXXX-XXXXX', 'server_name');$license->sendTelemetry('XXXXX-XXXXX-XXXXX-XXXXX', [
'event' => 'export_completed',
'format' => 'pdf',
'records' => 1500,
'timestamp' => date('c')
]);// Get product downloadables
$downloads = $license->getDownloadables('product-uuid');
// Get download URL
$result = $license->getDownloadUrl('downloadable-uuid', 'XXXXX-XXXXX-XXXXX-XXXXX');
// Redirect to download
return redirect()->to($result['data']['download_url']);use GetKeyManager\CodeIgniter\Libraries\GetKeyManagerLibrary;
$license = new GetKeyManagerLibrary();
try {
$result = $license->validateLicense($licenseKey);
if (!$result['success']) {
// Handle validation failure
$errorCode = $result['code'] ?? 0;
$message = $result['message'] ?? 'Validation failed';
switch ($errorCode) {
case 4001:
return "License not found";
case 4003:
return "License has expired";
case 4006:
return "Activation limit reached";
default:
return $message;
}
}
} catch (\Exception $e) {
log_message('error', 'License validation error: ' . $e->getMessage());
return "Unable to validate license";
}<?php
namespace GetKeyManager\CodeIgniter\Tests;
use CodeIgniter\Test\CIUnitTestCase;
use GetKeyManager\CodeIgniter\Libraries\GetKeyManagerLibrary;
class LicenseTest extends CIUnitTestCase
{
public function testCanInstantiateLibrary()
{
$license = new GetKeyManagerLibrary();
$this->assertInstanceOf(GetKeyManagerLibrary::class, $license);
}
public function testCanGenerateHardwareId()
{
helper('getkeymanager');
$hwid = generate_hardware_id();
$this->assertIsString($hwid);
$this->assertNotEmpty($hwid);
}
}All configuration options in app/Config/GetKeyManager.php:
| Option | Type | Default | Description |
|---|---|---|---|
apiKey |
string | '' | Your API key |
baseUrl |
string | https://api.getkeymanager.com | API base URL |
environment |
string | 'production' | Environment (production/staging/development) |
verifySignatures |
bool | true | Enable signature verification |
publicKey |
string|null | null | RSA public key for verification |
timeout |
int | 30 | HTTP timeout in seconds |
cacheEnabled |
bool | true | Enable response caching |
cacheTtl |
int | 300 | Cache TTL in seconds |
retryAttempts |
int | 3 | Number of retry attempts |
retryDelay |
int | 1000 | Retry delay in milliseconds |
loggingEnabled |
bool | false | Enable logging |
logThreshold |
int | 1 | Log threshold level (1-4) |
See the examples directory for complete working examples.
The CodeIgniter SDK proxies all methods from the base PHP SDK. See the full API reference.
- π§ Email: support@getkeymanager.com
- π Documentation: https://docs.getkeymanager.com
- π Issues: https://github.com/getkeymanager/codeigniter-sdk/issues
This SDK is open-sourced software licensed under the MIT license.