/** * Update last validated timestamp */ private function updateLastValidated($licenseId) { $sql = "UPDATE licenses SET last_validated_at = NOW() WHERE id = :id"; $stmt = $this->db->prepare($sql); $stmt->execute([':id' => $licenseId]); }
echo json_encode(['success' => true, 'data' => $result]); <?php // api/validate.php header('Content-Type: application/json'); require_once '../src/LicenseValidator.php';
public function prepare($sql) { return $this->connection->prepare($sql); }
class LicenseGenerator { private $db;
if (empty($data['license_key'])) { http_response_code(400); echo json_encode(['error' => 'License key is required']); exit; }
public function __construct() { $this->db = Database::getInstance(); }
php-license-key-system/ ├── config/ │ └── database.php ├── src/ │ ├── License.php │ ├── LicenseGenerator.php │ ├── LicenseValidator.php │ └── Database.php ├── api/ │ ├── generate.php │ ├── validate.php │ ├── activate.php │ └── deactivate.php ├── public/ │ └── example-client.php ├── sql/ │ └── schema.sql └── README.md 1. Database Schema ( sql/schema.sql ) CREATE DATABASE IF NOT EXISTS license_system; USE license_system; -- Licenses table CREATE TABLE IF NOT EXISTS licenses ( id INT AUTO_INCREMENT PRIMARY KEY, license_key VARCHAR(64) UNIQUE NOT NULL, product_id VARCHAR(50) NOT NULL, customer_name VARCHAR(100), customer_email VARCHAR(100), license_type ENUM('trial', 'monthly', 'yearly', 'perpetual') DEFAULT 'monthly', max_domains INT DEFAULT 1, status ENUM('active', 'inactive', 'expired', 'suspended') DEFAULT 'active', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, expires_at TIMESTAMP NULL, last_validated_at TIMESTAMP NULL, INDEX idx_license_key (license_key), INDEX idx_status (status), INDEX idx_expires_at (expires_at) );
echo json_encode($result); <?php // public/example-client.php class LicenseClient { private $apiUrl; private $licenseKey; private $domain; private $activationCode; private $cacheFile;