# Client/External Helper File Integration

With the main script now operational, we can integrate LicenseBox into your PHP application using the external/client helper file. This file can be generated from your LicenseBox admin panel and acts as a wrapper for the LicenseBox Client/External API.

The external/client helper file is a crucial component that provides the necessary requirements for your application to communicate with your LicenseBox server. By using this file, you can allow your users to activate, verify, and deactivate licenses, and they can also check for and download any updates that you have released from your LicenseBox admin panel.

Note: Please be advised that helper files are currently only available for the PHP programming language. However, you can access the comprehensive API documentation here which contains all API endpoints, parameters, and cURL snippets to aid you in making requests from your non-PHP applications.

### Getting Started

1. Log in to LicenseBox and add a new product from the menu.

2. Create a new API Key of type 'External' from the API Settings Page and provide it access to all the endpoints you want the client to access.

3. Go to Client Helper File generator from the Generate dropdown on the menu.

4. Select Product, API Key, API Language, and Verification Period (if you want to automatically verify the license at chosen interval) and choose if you want to allow Envato Purchase codes or not, then click Generate and copy the generated code.

5. Create a new folder in your PHP application root and save the generated code as whatever name you want to use, we are going to use `lb_helper.php` and the folder name as `includes`. So when you are done with this step you should have an "includes" folder with a "lb_helper.php" file.

6. Some things you would want to take a look at in the generated helper file are $root_path and $license_file path, the root_path should be pointed to your application root. If your includes folder which has the lb_helper.php file is already in your application root then you don't have to make any changes.

7. We are now done with the lb_helper.php file, It should now be included in your application.

8. If you want to only use the included pre-built PHP application installer, updater, activator or deactivator. Simply copy the `/install`, `/update`, `/activate` or `/deactivate` folder respectively from the `licensebox_integration_samples` folder and add it in your application root and you are good to go. You don't need to do anything else (except adding the background license check function in your main application entry file to do the actual license verification), you can still use all the available functions of the "lb_helper.php" file in your application but you would need to require it at the top on every page where you wish to use it.

   Note: In the `licensebox_integration_samples` folder, you will also find a sample WordPress plugin (useful if you are integrating licensebox in your wordpress plugin/theme) in which you can add your generated WordPress client/external helper file code as `lb_helper.php` file in the `includes` folder and test it out. It has both the license and updates system integrated. You can easily port the license and update system code from it into your WordPress plugin/theme or use it as a base.

9. Now, If you want to use all or any LicenseBox API helper functions in your complete application, you should go to your application entry file (index.php file) or (innit.php file) or any other file which all other files of your application require/include.

10. At the very top paste the following code:

        require_once 'includes/lb_helper.php';
        $api = new LicenseBoxExternalAPI();

    Note: lb_helper.php file on its own does nothing but it contains all the required functions and you can call them however you want.

11. Now you can call any available LicenseBox Helper file function from anywhere in your application, to learn more about all the available functions and what they do with live examples, add your generated Client/External helper file code as `lb_helper.php` file in the `includes` folder present inside `licensebox_api_usage_examples` folder and view the `external_api_examples.php` file.

12. For example, you can verify a license using `verify_license()` function and exit your application if the license is invalid. `verify_license()` can be directly called without any parameters when a local `.lic` license file exists, this file is created on successful activation by the `activate_license()` function.

        $res = $api->verify_license();
        if($res['status']!=true){
          die('Your license is invalid, please contact support.');
        }

13. You can also verify licenses based on the chosen verification period.

        $res = $api->verify_license(true);
        if($res['status']!=true){
          die('Your license is invalid, please contact support.');
        }

14. Now let us see an example of checking for new application updates.

        $res = $api->check_update();
        if($res['status']){
          echo "New ".$res['version']." update available.";
        }

There are a lot more ways in which you can use LicenseBox Client/External API in your application, see the `external_api_examples.php` file inside `licensebox_api_usage_examples` folder to learn more. If you are facing issues getting the integration to work, enable the Debug mode in the helper file by changing the `LB_API_DEBUG` value to `true`.

15. Finally, when you are done with the integration you should obfuscate your application as you may know readable/editable PHP code is not protected (as the user can modify the code) so you should obfuscate both your script entry file and the lb_helper file (if not, your full application with license and updates system integrated), You can use the in-built PHP obfuscator for that or you can also use paid software like ioncube but there are a lot of free PHP obfuscation tools available out there too.

### Using Integration Sample Scripts

To test the included integration samples, first add your generated external helper file as `lb_helper.php` inside the `includes` folder present in the `licensebox_integration_samples` folder

Note: As the name suggest these are only integration samples and may require additional changes to be used in a production environment.

#### 1. Activator (/activate folder)

This script creates a local `.lic` license file based on the provided valid license code and client name, once the user has activated the script or the `.lic` license file is created you can check the license using the `verify_license()` function in your application entry file as explained above.

#### 2. Installer (/install folder)

You can use a pre-made script installer, if you don't have a installer in your application, just add your SQL schema dump in the `database.sql` file and enjoy the all new script installer for your application with a built-in license activation system.

#### 3. Updater (/update folder)

This script will act as an updater for your application, just make sure you have the $root_path in `lb_helper.php` pointing to your application root, you can also pass your database details to automatically import update `.sql` file.

Note: Whenever you release any new update for your application you should also include the updated `lb_helper.php` file in the main update (.zip) file with the $current_version value changed to the new version otherwise the updater won't recognize if the script has already been updated or not. LicenseBox will extract/replace all the update files in your application root so make sure you push updates with the correct file structure.

#### 4. Deactivator (/deactivate folder)

This script deactivates and removes the locally stored `.lic` license file and it marks it's activation as inactive on the LicenseBox server, so that the client can activate the same license on some other domain in the future. This is a must have feature if you are planning to have single use licenses.

#### 5. Wordpress Sample Plugin (/licensebox-wp-sample folder)

You can also checkout the included sample wordpress plugin to see how licensebox can be integrated with a wordpress plugin, add your Wordpress External Helper File code as `lb_helper.php` file in the `includes` folder and create a plugin .zip file to install on your wordpress site. This plugin simply displays a dummy text in all posts footer when the license is active. When any new updates are available it will also show relevant notifications in the WordPress plugins page. You can easily port the license and updates system from it to your wordpress plugin/theme or you can use this plugin as a base for your next project.

#### ❮ Previous (Overview) Next (Internal Helper File Integration) ❯

Please mail us your feedback at support@licensebox.app
Follow us on twitter at @LicenseBoxApp for future product updates