PHP code example of getkey / licencephp

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();
        }
    }
}
 

'licence' => [
    'endpoint' => env('LICENCE_ENDPOINT', 'https://getkey.my.id/api/v1/getLicence'),
],
 

use App\Traits\ManagesLicense;

class YourController extends Controller
{
    use ManagesLicense;

    public function yourMethod()
    {
        $scriptName = "Licence1";

        // Manage and validate the licence
        $result = $this->manageAndValidateLicense($scriptName);

        if ($result === true) {
            // Logic for successful validation
            return view('welcome');
        } else {
            // Logic for failed validation
            return response()->json(['error' => $result], 500);
        }
    }
}