PHP code example of sdkey / sdk

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

    

sdkey / sdk example snippets




use Sdkey\SdkeyClient;
use Sdkey\SdkeyError;

$client = new SdkeyClient(
    apiBaseUrl: 'https://api.sdkey.dev',
    appId: 'YOUR_APP_ID',
    appVersion: '1.0.0',
    appPublicKeyB64: 'YOUR_APP_PUBLIC_KEY_BASE64',
);

try {
    // hwid is optional — omit for web clients
    $result = $client->validate('SDKY-XXXX-XXXX-XXXX-XXXX', 'machine-hwid');
    if ($result->success) {
        echo "licensed {$result->status} tier={$result->subscriptionTier} {$result->message}\n";
    } else {
        fwrite(STDERR, "denied {$result->code} {$result->message}\n");
    }
} catch (SdkeyError $err) {
    fwrite(STDERR, "{$err->code} {$err->getMessage()}\n");
    throw $err;
}

$auth = $client->register('player1', 'password123', licenseKey: 'SDKY-XXXX');
// or: $client->login('player1', 'password123');
// or: $client->upgrade('player1', 'SDKY-HIGHER'); // no password

echo $auth->sessionToken; // opaque user session (7-day TTL), not crypto sessionId