Basic Protection
Protect your script in about 5 minutes by including core files and calling one license verification function
Application Protection - Basic
This integration guide will help you to protect your script by simply including core files and calling one license verification function. It takes about 5 minutes to setup and is a perfect choice for developers with basic PHP skills.
Including Files
Important!
Always place /SCRIPT directory in the root directory of your script.
Just copy whole /SCRIPT directory to the root directory of your script and include apl_core_configuration.php and apl_core_functions.php files in your script using this code:
require_once("SCRIPT/apl_core_configuration.php");
require_once("SCRIPT/apl_core_functions.php");
Attention: you can add custom files and subdirectories to /SCRIPT directory as long as /SCRIPT is located in the root directory of your script.
Since most PHP scripts usually have main settings file, this code can be added right to settings file. This way, you don't need to include code to each file separately.
Configuring Settings
Important!
Always modify default encryption salt (APL_SALT) in configuration file.
Basic protection guide uses FILE to store license signature. See advanced protection guide for DATABASE example.
All LicenTra settings for your application are stored in /SCRIPT/apl_core_configuration.php file (rename it from apl_core_configuration_sample.php to apl_core_configuration.php first). Since this file must be included in each application you want to protect, be sure to use a different encryption salt every time. When automatic configuration file generator at Extra Tools » Configuration Generator is used, a random salt is generated automatically. As a result, if someone hacks one of your applications, the other ones still remain protected. The copy of default configuration file is below:
<?php
//MAIN CONFIG FILE OF LICENTRA. CAN BE EDITED MANUALLY OR GENERATED USING Extra Tools > Configuration Generator TAB IN LICENTRA DASHBOARD. THE FILE MUST BE INCLUDED IN YOUR SCRIPT BEFORE YOU PROVIDE IT TO USER.
//-----------BASIC SETTINGS-----------//
//Random salt used for encryption. It should contain random symbols (16 or more recommended) and be different for each application you want to protect. Cannot be modified after installing script.
define("APL_SALT", "some_random_text");
//The URL (without / at the end) where LicenTra is installed on your server. No matter how many applications you want to protect, a single installation is enough.
define("APL_ROOT_URL", "https://www.example.com/apl");
//Unique numeric ID of product that needs to be licensed. Can be obtained by going to Products > View Products tab in LicenTra dashboard and selecting product to be licensed. At the end of URL, you will see something like products_edit.php?product_id=NUMBER, where NUMBER is unique product ID. Cannot be modified after installing script.
define("APL_PRODUCT_ID", 1);
//Time period (in days) between automatic license verifications. The lower the number, the more often license will be verified, but if many end users use your script, it can cause extra load on your server. Available values are between 1 and 365. Usually 7 or 14 days are the best choice.
define("APL_DAYS", 7);
//Place to store license signature and other details. "DATABASE" means data will be stored in MySQL database (recommended), "FILE" means data will be stored in local file. Only use "FILE" if your application doesn't support MySQL. Otherwise, "DATABASE" should always be used. Cannot be modified after installing script.
define("APL_STORAGE", "FILE");
//Name of table (will be automatically created during installation) to store license signature and other details. Only used when "APL_STORAGE" set to "DATABASE". The more "harmless" name, the better. Cannot be modified after installing script.
define("APL_DATABASE_TABLE", "user_data");
//Name and location (relative to directory where "apl_core_configuration.php" file is located, cannot be moved outside this directory) of file to store license signature and other details. Can have ANY name and extension. The more "harmless" location and name, the better. Cannot be modified after installing script. Only used when "APL_STORAGE" set to "FILE" (file itself can be safely deleted otherwise).
define("APL_LICENSE_FILE_LOCATION", "signature/license.key.example");
//Notification to be displayed when connection to server can't be established. Other notifications will be automatically fetched from server.
define("APL_NOTIFICATION_NO_CONNECTION", "Can't connect to licensing server.");
//Notification to be displayed when response received from server is invalid. Other notifications will be automatically fetched from server.
define("APL_NOTIFICATION_INVALID_RESPONSE", "Invalid server response.");
//Notification to be displayed when updating database fails. Only used when APL_STORAGE set to DATABASE.
define("APL_NOTIFICATION_DATABASE_WRITE_ERROR", "Can't write to database.");
//Notification to be displayed when updating license file fails. Only used when APL_STORAGE set to FILE.
define("APL_NOTIFICATION_LICENSE_FILE_WRITE_ERROR", "Can't write to license file.");
//Notification to be displayed when installation wizard is launched again after script was installed.
define("APL_NOTIFICATION_SCRIPT_ALREADY_INSTALLED", "Script is already installed (or database not empty).");
//Notification to be displayed when license could not be verified because license is not installed yet or corrupted.
define("APL_NOTIFICATION_LICENSE_CORRUPTED", "License is not installed yet or corrupted.");
//Notification to be displayed when license verification does not need to be performed. Used for debugging purposes only, should never be displayed to end user.
define("APL_NOTIFICATION_BYPASS_VERIFICATION", "No need to verify");
//-----------ADVANCED SETTINGS-----------//
//Secret key used to verify if configuration file included in your script is genuine (not replaced with 3rd party files). It can contain any number of random symbols and should be different for each application you want to protect. You should also change its name from "APL_INCLUDE_KEY_CONFIG" to something else, let's say "MY_CUSTOM_SECRET_KEY"
define("APL_INCLUDE_KEY_CONFIG", "some_random_text");
//IP address of your LicenTra installation. If IP address is set, script will always check if "APL_ROOT_URL" resolves to this IP address (very useful against users who may try blocking or nullrouting your domain on their servers). However, use it with caution because if IP address of your server is changed in future, old installations of protected script will stop working (you will need to update this file with new IP and send updated file to end user). If you want to verify licensing server, but don't want to lock it to specific IP address, you can use APL_ROOT_NAMESERVERS option (because nameservers change is unlikely).
define("APL_ROOT_IP", "");
//Nameservers of your domain with LicenTra installation (only works with domains and NOT subdomains). If nameservers are set, script will always check if "APL_ROOT_NAMESERVERS" match actual DNS records (very useful against users who may try blocking or nullrouting your domain on their servers). However, use it with caution because if nameservers of your domain are changed in future, old installations of protected script will stop working (you will need to update this file with new nameservers and send updated file to end user). Nameservers should be formatted as an array. For example: array("ns1.example.com", "ns2.example.com"). Nameservers are NOT CAse SensitIVE.
//define("APL_ROOT_NAMESERVERS", array()); //ATTENTION! THIS FEATURE ONLY WORKS WITH PHP 7.0 AND HIGHER, ONLY UNCOMMENT THIS LINE IF PROTECTED SCRIPT WILL RUN ON COMPATIBLE SERVER!
//When option set to "YES", script files and MySQL data will be deleted when illegal usage is detected. This is very useful against users who may try using pirated software; if someone shares his license with 3rd parties (by sending it to a friend, posting on warez forums, etc.) and you cancel this license, LicenTra will try to delete all script files and any data in MySQL database for everyone who uses cancelled license. For obvious reasons, data will only be deleted if license is cancelled. If license is invalid or expired, no data will be modified. Use at your own risk!
define("APL_DELETE_CANCELLED", "");
//When option set to "YES", script files and MySQL data will be deleted when cracking attempt is detected. This is very useful against users who may try cracking software; if some unauthorized changes in core functions are detected, LicenTra will try to delete all script files and any data in MySQL database. Use at your own risk!
define("APL_DELETE_CRACKED", "YES");
//When option set to "YES", ALL files and MySQL data will be deleted when cracking attempt is detected. This option only works when APL_DELETE_CRACKED is set to "YES". The main difference between standard (used by default when APL_DELETE_CRACKED is set to "YES") and GOD mode is that GOD mode deletes not only script files, but also all other files from user's website (including other scripts, custom user files, etc.)
define("APL_GOD_MODE", "YES");
//-----------NOTIFICATIONS FOR USER INPUT VERIFICATIONS. SAFE TO DISPLAY TO END USER-----------//
define("APL_USER_INPUT_NOTIFICATION_INVALID_ROOT_URL", "User input error: Invalid installation URL (it should have a valid scheme and no / symbol at the end)");
define("APL_USER_INPUT_NOTIFICATION_EMPTY_LICENSE_DATA", "User input error: empty license data (licensed email or license code should be provided)");
define("APL_USER_INPUT_NOTIFICATION_INVALID_EMAIL", "User input error: invalid licensed email (it should be a valid email address)");
define("APL_USER_INPUT_NOTIFICATION_INVALID_LICENSE_CODE", "User input error: invalid license code (it should be a code in plain text)");
//-----------NOTIFICATIONS FOR DEBUGGING PURPOSES ONLY. SHOULD NEVER BE DISPLAYED TO END USER-----------//
define("APL_CORE_NOTIFICATION_INVALID_SALT", "Configuration error: invalid or default encryption salt");
define("APL_CORE_NOTIFICATION_INVALID_ROOT_URL", "Configuration error: invalid root URL of LicenTra installation");
define("APL_CORE_NOTIFICATION_INVALID_PRODUCT_ID", "Configuration error: invalid product ID");
define("APL_CORE_NOTIFICATION_INVALID_VERIFICATION_PERIOD", "Configuration error: invalid license verification period");
define("APL_CORE_NOTIFICATION_INVALID_STORAGE", "Configuration error: invalid license storage option");
define("APL_CORE_NOTIFICATION_INVALID_TABLE", "Configuration error: invalid MySQL table name to store license signature");
define("APL_CORE_NOTIFICATION_INVALID_LICENSE_FILE", "Configuration error: invalid license file location (or file not writable)");
define("APL_CORE_NOTIFICATION_INVALID_ROOT_IP", "Configuration error: invalid IP address of your LicenTra installation");
define("APL_CORE_NOTIFICATION_INVALID_ROOT_NAMESERVERS", "Configuration error: invalid nameservers of your LicenTra installation");
define("APL_CORE_NOTIFICATION_INVALID_DNS", "License error: actual IP address and/or nameservers of your LicenTra installation don't match specified IP address and/or nameservers");
//-----------SOME EXTRA STUFF. SHOULD NEVER BE REMOVED OR MODIFIED-----------//
define("APL_DIRECTORY", __DIR__);
While each option is explained in configuration file itself, the table below contains extra notes on the most important ones. All settings marked by * are required, while other settings are optional.
| Option | Description | Notes |
|---|---|---|
APL_SALT* |
Random salt used for encryption. It should contain 16 or 24 random symbols and be different for each application you want to protect. | Cannot be modified after installing script. |
APL_ROOT_URL* |
The URL (without / at the end) where LicenTra is installed on your server. No matter how many applications you want to protect, a single installation is enough. | |
APL_PRODUCT_ID* |
Unique numeric ID of product that needs to be licensed. Can be obtained by going to Products » View Products tab in LicenTra dashboard and selecting product to be licensed. At the end of URL, you will see something like products_edit.php?product_id=NUMBER, where NUMBER is unique product ID. |
Cannot be modified after installing script. |
Calling Functions
Important!
$MYSQLI_LINK is only needed if your script requires MySQL connection.
$MYSQLI_LINK should always be local MySQL connection on user's server (never include MySQL credentials of your LicenTra installation).
In order to protect your application, you need to call one or more of LicenTra functions inside your code. Here's the list of essential functions (including type of data each function returns), their descriptions and working examples. These functions must be called for basic protection to work.
| Function | Arguments | Returned Data | Notes |
|---|---|---|---|
aplInstallLicense |
$ROOT_URL, $CLIENT_EMAIL, $LICENSE_CODE, $MYSQLI_LINK (optional) |
array | Installs script for licensed users, aborts installation for non-licensed users. |
aplVerifyLicense |
$MYSQLI_LINK (optional), $FORCE_VERIFICATION (optional) |
array | Verifies license status, allows using script for licensed users, aborts script execution for non-licensed users. |
aplInstallLicense
Function: aplInstallLicense($ROOT_URL, $CLIENT_EMAIL, $LICENSE_CODE, $MYSQLI_LINK).
Description: verifies if license exists, is active, and meets installation requirements. Activates script on success, returns an array with error messages otherwise.
Arguments: $ROOT_URL (full URL of script installation without / at the end), $CLIENT_EMAIL (licensed email address for personal licenses), $LICENSE_CODE (license code for anonymous licenses), $MYSQLI_LINK (only when MySQL database is used).
Returned data: array with keys notification_case and notification_text.
Should be used in: installer (needs to be called once during script installation).
Additional notes: When personal license is used (license code not available), $LICENSE_CODE should be empty. When anonymous license is used (user's email unknown), $CLIENT_EMAIL should be empty.
Array's key notification_case value will always be notification_license_ok when operation succeeds.
Example:
//install personal (email-based) license without using MySQL database
$license_notifications_array = aplInstallLicense("http://www.clientdomain.com", "client@email.com", "");
if ($license_notifications_array['notification_case'] == "notification_license_ok") //'notification_license_ok' case returned - operation succeeded
{
echo "Script is installed and ready to use!";
}
else //Other case returned - operation failed
{
echo "Installation failed because of this reason: " . $license_notifications_array['notification_text'];
exit();
}
aplVerifyLicense
Function: aplVerifyLicense($MYSQLI_LINK, $FORCE_VERIFICATION).
Description: verifies if license exists, is active, and meets usage requirements. Allows using script on success, returns error message otherwise (optionally, deletes user data when license is cancelled).
Arguments: $FORCE_VERIFICATION (0 to use default verification, 1 to force verification), $MYSQLI_LINK (only when MySQL database is used).
Returned data: array with keys notification_case and notification_text.
Should be used in: all files (except script installer when no license signature is stored yet) for maximum protection, or at least the most important files of your script.
Additional notes: Array's key notification_case value will always be notification_license_ok when operation succeeds.
There might be some cases when you don't want X days/weeks/months/years to pass since last verification, and need to force license validation right now. This way, set $FORCE_VERIFICATION value to 1 and LicenTra will connect to your server to force license validation. Use this option in extraordinary situations only, otherwise protected script will connect to your server every time it's in use (which means high server load).
Example:
//verify license (LicenTra will determine when connection to your server is needed)
$license_notifications_array = aplVerifyLicense();
if ($license_notifications_array['notification_case'] == "notification_license_ok") //'notification_license_ok' case returned - operation succeeded
{
//display some success message or simply do nothing (so user can continue using his script)
}
else //Other case returned - operation failed
{
echo "License verification failed because of this reason: " . $license_notifications_array['notification_text'];
exit();
}
Summary
Here's the short summary of all the actions (listed step-by-step) needed to fully protect your application.
- include
apl_core_configuration.phpandapl_core_functions.phpfiles; - call LicenTra functions inside your application;