If you sell PHP applications or software that needs to be restricted to licensed customers, you need a way to verify licenses and enforce the corresponding entitlements in your code.
For a simple application, this can mean checking whether a license key is valid before allowing access to a particular function. As the product grows, licensing may also need to handle subscription periods, feature entitlements, activations, and offline environments.
This guide shows how to implement software licensing in PHP using Devolens, including the basic code required to activate and verify a license.
At its simplest, software licensing code checks whether a customer has a valid license before allowing the application or a particular feature to run.
The licensing flow typically looks like this:
The important part is that the licensing check becomes part of your application's normal execution flow. For example, you might check a license before enabling a premium feature rather than simply checking once when the application is installed.
For a broader explanation of how licensing systems work, see our guide to how software licensing works.
You can implement the licensing API directly in PHP, but using an SDK avoids having to build the API integration and activation logic yourself.
Devolens provides a PHP library that can be used to activate license keys from PHP applications. The current PHP library supports license key activation through the Devolens API.
The basic setup is straightforward. Download the PHP library and include it in your application:
<?php
require_once('Cryptolens.php');
You then need the values that identify your licensing setup:
The access token and product ID are associated with your Devolens account and product. The license key normally comes from the customer or from the provisioning system that delivers licenses to your application.
Once the library is included, you can activate a license using the cryptolens_activate function.
A basic example looks like this:
<?php
require_once('Cryptolens.php');
$activate = cryptolens_activate(
// Access token
'YOUR_ACCESS_TOKEN',
// Product ID
1234,
// License Key
'AAAAA-BBBBB-CCCCC-DDDDD',
// Machine Code
'YOUR_MACHINE_CODE'
);
if ($activate) {
echo "License is valid.";
} else {
echo "License is not valid.";
}
?>
The example uses placeholder values deliberately. Your access token, product ID, license key, and machine code should come from your own licensing setup rather than being copied from an example.
The PHP library returns a boolean indicating whether the activation attempt was successful.
For more detailed implementation examples and the parameters available to the API, refer to the software licensing implementation guide.
Activating a license is only one part of implementing software licensing. Your application also needs to use the result of the license check to control access.
For example, you could check the license before allowing a customer to use a premium function:
if (!$activate) {
exit("A valid license is required to use this feature.");
}
// Premium functionality
runPremiumFeature();
A more useful implementation will usually distinguish between different entitlements rather than treating the license as simply valid or invalid.
For example, you might have:
This keeps the licensing logic connected to the commercial model of your product. Your application decides what the customer can use based on the license information rather than maintaining a separate set of access rules.
Machine binding can be useful when you want to restrict a license to a particular server or installation.
The PHP library does not calculate the machine code itself, so your application needs to provide an appropriate value when activation is performed.
The value you use depends on how your PHP application is deployed. For example, a server based application may use an identifier associated with the installation rather than relying on a particular hardware component.
This is worth considering carefully before implementing it. If the identifier changes during a normal server migration or reinstallation, legitimate customers may unexpectedly lose access to their license.
A production licensing implementation usually needs to account for more than the initial activation request.
For example, you may need to decide:
These decisions are part of the licensing architecture rather than PHP specific code.
If your application needs to work without an internet connection, Devolens supports offline licensing using signed license files.
For a small PHP application, the basic implementation can be relatively short. The more important decision is how that initial license check fits into the rest of the application.
A useful implementation separates licensing from the business logic wherever possible. Your application can retrieve the license state once and then use that information to determine which functionality should be available.
This makes it easier to change licensing models later without spreading licensing checks throughout the entire codebase.
If you are implementing a complete licensing system rather than adding a single license check, it is also worth considering how license creation, activation, renewals, expiry, and entitlement changes will be handled. These are the parts that tend to create ongoing maintenance work when licensing is implemented entirely inside the application.
Implementing software licensing in PHP does not require a large amount of application code. The core flow is to obtain a license key, activate it through the licensing system, and use the result to enforce the appropriate access rules in your application.
The implementation can then be extended to support different licensing models, feature entitlements, machine binding, and offline environments as your product requires.
With the basic licensing layer separated from the rest of your PHP application, you can change how licenses are issued and managed without having to redesign the application's core functionality.
Deploy licensing with a leading software licensing provider without long implementation cycles or added operational overhead.