PHP code example of getkeymanager / codeigniter-sdk
1. Go to this page and download the library: Download getkeymanager/codeigniter-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
getkeymanager / codeigniter-sdk example snippets
helper('getkeymanager');
$state = resolve_license_state($key);
if ($state->isActive()) {
// License is fully active
} elseif ($state->isInGracePeriod()) {
// Grace period - network issues
} else {
// Invalid
}
// 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
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
}
public string $apiKey;
public function __construct()
{
parent::__construct();
$this->apiKey = getenv('LICENSE_MANAGER_API_KEY');
}
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);
}
}
}
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-d', $data);
}
}
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-
public array $aliases = [
'license' => \App\Filters\LicenseFilter::class,
];
// 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";
}
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);
}
}