1. Go to this page and download the library: Download getkey/licencephp library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
getkey / licencephp example snippets
trait ManagesLicense
{
protected $licenceManager;
protected $pemFilePath;
// Automatically initialize when the trait is used
public function __construct()
{
$this->initializeLicenseManager();
}
// Initialize the LicenseManager instance
protected function initializeLicenseManager($endpoint = null)
{
$endpoint = $endpoint ?: config('services.licence.endpoint');
$this->licenceManager = new LicenseManager($endpoint);
}
// Set the PEM file path based on the script name
protected function setPemFilePath($scriptName)
{
$this->pemFilePath = storage_path('licences/' . $scriptName . '.pem');
}
// Get the PEM file path
protected function getPemFilePath()
{
return $this->pemFilePath;
}
// Combined method to manage and validate the licence
public function manageAndValidateLicense($scriptName)
{
try {
if (!$this->licenceManager) {
$this->initializeLicenseManager();
}
// Set the PEM file path using the script name
$this->setPemFilePath($scriptName);
$pemFilePath = $this->getPemFilePath();
// Manage the licence (fetch, save, and validate)
$this->licenceManager->manageLicense($scriptName, $pemFilePath);
// Validate the PEM file content
return $this->licenceManager->verifyPemContent($pemFilePath);
} catch (Exception $e) {
return $e->getMessage();
}
}
}