Integrating in PHP
A guide integrating the licensing system in your PHP app.
Introduction
This guide will help you integrate the OmegaLicensing system into your PHP application.
This guide assumes the usage of PHP 8.0 or higher.
It also assumes the prior setup of the OmegaLicensing web API. That implies that it's available on a public URL and you have a license key to validate.
Code
Add the following code in the initialization of your PHP application.
<?php
function validateLicense($apiUrl, $licenseKey, $productId) {
$url = "{$apiUrl}/licenses/validate?key={$licenseKey}&product={$productId}";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($response === false) {
echo "Error validating license: " . curl_error($ch);
exit(1);
}
curl_close($ch);
$data = json_decode($response, true);
if (isset($data['valid']) && $data['valid']) {
echo "License key is valid.\n";
} else {
echo "Invalid license key. Exiting program.\n";
exit(1);
}
}
// Replace this API URL with your own api url.
$API_URL = "http://your-api-url";
// Replace this license key with the one you want to validate.
$LICENSE_KEY = "user-submitted-key";
// Replace this with the product ID of the product you want to validate the license for.
$PRODUCT_ID = 1;
validateLicense($API_URL, $LICENSE_KEY, $PRODUCT_ID);