false, 'message' => 'Invalid request method.']); exit; $license_key = $_POST['license_key'] ?? ''; $domain = $_POST['domain'] ?? ''; if (empty($license_key) || empty($domain)) echo json_encode(['valid' => false, 'message' => 'Missing required parameters.']); exit; // Connect to your database $pdo = new PDO('mysql:host=localhost;dbname=license_db', 'username', 'password'); // Check if license exists and is active $stmt = $pdo->prepare("SELECT * FROM licenses WHERE license_key = ? AND status = 'active'"); $stmt->execute([$license_key]); $license = $stmt->fetch(); if (!$license) echo json_encode(['valid' => false, 'message' => 'Invalid or suspended license key.']); exit; // Check expiration date if ($license['expires_at'] && strtotime($license['expires_at']) < time()) echo json_encode(['valid' => false, 'message' => 'License has expired.']); exit; // Check current activations $stmt = $pdo->prepare("SELECT COUNT(*) FROM activations WHERE license_id = ?"); $stmt->execute([$license['id']]); $current_activations = $stmt->fetchColumn(); // Check if this domain is already activated $stmt = $pdo->prepare("SELECT * FROM activations WHERE license_id = ? AND domain = ?"); $stmt->execute([$license['id'], $domain]); $already_active = $stmt->fetch(); if (!$already_active) if ($current_activations >= $license['max_activations']) echo json_encode(['valid' => false, 'message' => 'Activation limit reached.']); exit; // Register new activation $stmt = $pdo->prepare("INSERT INTO activations (license_id, domain) VALUES (?, ?)"); $stmt->execute([$license['id'], $domain]); echo json_encode(['valid' => true, 'message' => 'License validated successfully.']); Use code with caution. Step 3: Implementing the Client-Side Verification
This guide covers how to build, host, and distribute a PHP licensing system using GitHub and a central validation server. Understanding the Architecture php license key system github
These repositories include both the (where you generate keys and manage customers) and the Client (the code that goes into your product). false, 'message' => 'Invalid request method
The client code lives inside your distributed application. It sends the user's entered license key and the current domain to your API server. AND status = 'active'")