PHP code example of permitcore / sdk

1. Go to this page and download the library: Download permitcore/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/ */

    

permitcore / sdk example snippets



PermitCore\PermitCoreClient;

$client = new PermitCoreClient('https://your-instance.com');
$result = $client->validate('PERMIT-XXXX-XXXX-XXXX-XXXX');

if ($result->isValid) {
    echo 'Valid! Product: ' . $result->productName . PHP_EOL;

    if ($result->hasFeature('export')) {
        enableExport();
    }
}

$result = $client->validate($licenseKey);

// isValid                  bool
// productName              ?string
// remainingActivations     ?int
// expiresAt                ?string  (ISO 8601)
// features                 ?array   (e.g. ['export', 'api'])
// isTrial                  bool
// trialDaysRemaining       ?int
// nodeLocked               bool
// offlineGraceDays         ?int
// minVersion               ?string
// maxVersion               ?string
// vendorWarning            ?string
// message                  ?string
// isOffline                bool     (true when served from local cache)
// productId                ?string  (the license's real product GUID; see "Product scoping" below)

$result = $client->activate(
    licenseKey: 'PERMIT-XXXX-XXXX-XXXX-XXXX',
    deviceId:   null,          // auto-generated HWID when null
    deviceName: 'Production Server #1'
);

if (!$result->isValid) {
    die('Activation failed: ' . $result->message);
}

$result = $client->validate($licenseKey, expectedProductId: 'your-product-guid-here');

if ($result->errorCode === 'WrongProduct') {
    die('This key was not issued for this product.');
}

// Record a single API call
$recorded = $client->meter('PERMIT-XXXX-XXXX-XXXX-XXXX', 'api_call');

// Record bulk usage with metadata
$recorded = $client->meter(
    licenseKey: 'PERMIT-XXXX-XXXX-XXXX-XXXX',
    eventName:  'export',
    quantity:   5,
    meta:       ['format' => 'pdf', 'pages' => 12]
);

// Check out a seat at session start
$session = $client->checkout('PERMIT-XXXX-XXXX-XXXX-XXXX');
if (!$session->success) {
    die('No seats available: ' . $session->message);
}

$token = $session->sessionToken;

// Heartbeat every 4–5 minutes to keep the seat alive
$client->heartbeat($token);

// Release the seat when done
$client->checkin($token);

// Pure local verification — no network call. Never throws.
$result = $client->verifyOfflineToken($token, $publicKeyBase64);

if ($result['isValid']) {
    echo 'Valid! Product: ' . $result['productName'] . PHP_EOL;
    echo 'Expires: ' . $result['expiresAt'] . PHP_EOL;
} else {
    echo 'Invalid: ' . $result['message'] . PHP_EOL;
}

// Verify + bind to this device + persist locally (call once, e.g. at install time)
$result = $client->activateOffline($token, $publicKeyBase64, $deviceId);

// On every later launch — no token needed, reads the local cache, still no network call
$result = $client->validateOffline($deviceId);

// Optional: ask the server to verify the token AND check its revocation status (

$result = $client->validate($licenseKey);

$myVersion = '2.3.0';
if ($result->minVersion !== null && version_compare($myVersion, $result->minVersion, '<')) {
    die("Please update to version {$result->minVersion} or newer.");
}
if ($result->maxVersion !== null && version_compare($myVersion, $result->maxVersion, '>')) {
    die("This build ({$myVersion}) is not licensed for versions above {$result->maxVersion}.");
}

$result = $client->validate($licenseKey); // falls back to cache automatically

if (!$result->isValid) {
    die('License invalid: ' . $result->message);
}

if ($result->isOffline) {
    // Server unreachable — running on cached result
    showNotice('Running in offline mode. Connect to the internet to refresh your license.');
}

$client = new PermitCoreClient(
    baseUrl:            'https://your-instance.com',
    enableOfflineCache: true,   // default — set false to always 
bash
unzip permitcore-sdk-php.zip -d permitcore-sdk-php
cd your-project
composer