PHP Projects
SunLicense Integration Guide for PHP Projects
Prerequisites
Integration Steps
1. Create License Validator Class
<?php
class SunLicenseValidator {
private string $licenseKey;
private int $productId;
private string $apiUrl;
private string $version;
public function __construct(string $licenseKey, int $productId, string $version = '1.0.0') {
$this->licenseKey = $licenseKey;
$this->productId = $productId;
$this->version = $version;
$this->apiUrl = 'YOUR_API_URL/api/v1/validate';
}
public function validate(): bool {
$data = [
'licenseKey' => $this->licenseKey,
'productId' => $this->productId,
'productVersion' => $this->version,
'hwid' => $this->getHWID() // Optional
];
$ch = curl_init($this->apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
throw new Exception('License validation failed: ' . $response);
}
return true;
}
private function getHWID(): string {
// Implement your HWID generation logic here
return 'YOUR-HWID';
}
}2. Implementation Example
3. Using with Framework (Laravel Example)
Best Practices
Common Issues and Solutions
Last updated