We can use a PHP function to generate a license key based on the user's details. For example:
// Server-side validation endpoint (validate.php) header('Content-Type: application/json'); $licenseKey = $_POST['license_key'] ?? ''; $domain = parse_url($_POST['domain'] ?? '', PHP_URL_HOST); // 1. Database Lookup (Pseudo-code) $license = findLicenseInDatabase($licenseKey); if (!$license || $license['status'] !== 'active') echo json_encode(['status' => 'invalid', 'message' => 'License is inactive or does not exist.']); exit; // 2. Prepare Payload $responseData = [ 'status' => 'valid', 'license_key' => $licenseKey, 'domain' => $domain, 'expires_at' => $license['expires_at'], 'timestamp' => time() ]; $payload = json_encode($responseData); // 3. Sign the payload using OpenSSL private key $privateKey = openssl_pkey_get_private(file_get_contents('private_key.pem')); openssl_sign($payload, $signature, $privateKey, OPENSSL_ALGO_SHA256); echo json_encode([ 'data' => $payload, 'signature' => base64_encode($signature) ]); Use code with caution. Step 3: Client-Side Remote Phone Home (Client Side)
$data = json_decode($response, true); return $data['valid'] ?? false; php license key system github hot
800+ stars, 200+ forks Why it's hot: Framework-agnostic. You can drop it into vanilla PHP, Slim, or Symfony.
// Example: SLK-AA9A9A-AA-99 $prefix = 'PRO'; $template = 'AAAA-9999-AAAA'; // Generate secure random bytes $key = $prefix . '-' . generateSecureKey($template); Use code with caution. 2. The Server-Side Validation (The "Phone Home" Method) We can use a PHP function to generate
<?php // generate_license.php $payload = json_encode([ 'expires' => strtotime('+1 year'), 'domains' => ['example.com', '*.example.org'], 'features' => ['backup', 'export'], 'user' => 'user@example.com' ]); $privateKey = sodium_crypto_sign_secretkey(file_get_contents('private.key')); $signature = sodium_crypto_sign_detached($payload, $privateKey); $license = base64_encode($payload . '::' . $signature); echo "License Key: " . chunk_split($license, 20, '-');
By hiding the $githubToken on your private license server, clients never see your GitHub repository credentials, keeping your source code fully protected. 4. Hardening Your License System Against "Nulled" Cracks '', PHP_URL_HOST); // 1
Simple licensing needs where activation is handled manually. 3. Devolens License Key System
Your PHP application (the one being protected) needs to "phone home" to the license server.