ionCube Product Setup - External License File

Overview
This is a brief tutorial on how to set up a product in ionCube to use an external license file. For a better understanding of this you should consult your ionCube documentation. Note that this tutorial assumes the Windows GUI version of ionCube.
1. Add product to ionCube
Firstly, you need to add your product to ionCube. Simply browse for folder on hard drive and add on the source screen:

2. Restrictions - External License File
Next, click the restrictions tab and view the "License File" section at the bottom:


Check both checkboxes, enter a license file name and also a unique passphrase. This should be UNIQUE for each product:


Note that the passphrase and license name you enter here will be the same as the ones you enter when setting up a product in Maian Cube.
3. Generate License File
At this point the software will be encoded to use an external license file. You MUST therefore include a license file when you offer your product for download or else the system will not run. This is accomplished by using the "Create License" option. Accessible via "Licensing > Create License" from the menu:


You should create the license in your product installation. Clicking "Create License" will do this for you. Make sure the path is correct to your project folder:

4. License Properties
When creating a license file, it's a good idea to have some properties in place to help determine if the license is a commercial one or the default one. For example, you have some features locked in your product that you want unlocked when a user generates a new license.

So, lets say you want to offer your product as a download so people can evaluate it's working ok, but you want to restrict certain functions from working. This is where the ionCube properties come in.

In the ionCube documentation, section 5.1 has information relating to "Retrieving Properties in an Encoded File", which is exactly what you need to do this, so lets look at this in more detail.
5. Loader API
The ionCube Loader contains an API providing various functions and constants that may be useful in PHP scripts. The function we are interested in is the "ioncube_file_properties" function.

This function returns an associative array consisting of file properties that were added to the encoded file with the Encoder --property or -properties options. Only properties defined in the calling script are returned.
6. Add Property to License in ionCube
Lets add a property into ionCube called "versiontype" and lets have the value set as "locked". It's worth pointing out that you don't have to add properties in ionCube, this is just to give you a better understanding of how it works.

In ionCube click the "License Settings" icon (or select from the "Project" menu):


This launches the license settings. So, into the "Key" box type "versiontype" and into the "Value" box type "locked". Then click ADD:


You now have something like this:


We won't touch on "Enforce" and "Expose" here. These are covered in other areas and also in the ionCube docs. For now, don't check either, simply click "OK" to close window.
7. Re-Generate License File
Once again click to "Generate License" file as detailed in part 3. Now you'll see the properties you created in the window like this:


When the license file is now created the "versiontype" property will be embedded in the license with the value of "locked".
8. Property Checking via Loader API
Ok, so now our license file contains the property we created we can check for this in our PHP file via the ionCube "ioncube_file_properties" loader API function. If the property exists and it's value is "locked", it's the restricted version. Here is a code example:

$icprop = ioncube_file_properties();
if (isset($icprop['versiontype']['value']) && $icprop['versiontype']['value'])==locked) {
  // software locked..do appropriate action.
} else {
  // software unlocked..do appropriate action.
}
A more complex example might be: if (function_exists('ioncube_file_properties')) {
  $icprop = ioncube_file_properties();
  if (isset($icprop['versiontype']['value'])) {
    switch ($icprop['versiontype']['value']) {
      case 'locked':
        // locked, do something..
        break;
      case 'unlocked':
        // Unlocked, do appropriate action..
        break;
      default:
        // Unknown, do appropriate action..
        break;
    }
  } else {
    // property doesn't exist, do appropriate action..
  }
}
We are not going to go over the PHP functions/code used here. A basic understanding of PHP is assumed. So, basically you check for the value of the property and do an appropriate action. You can have as many properties as you need.

You are probably wondering how the "unlocked" value above is possible above if the value in the property was set to "locked"? Read the next section and all will become clear.
9. Maian Cube Properties
When you set up your product in Maian Cube, you enter the property values that will be included in the new license file when it is downloaded by a visitor. So, in the example above, you could enter "versiontype" with the value now as "unlocked". When your script/software checks the property values in the license it will now be unlocked.

Note that you don't have to add properties in the ionCube interface. You can just add them in Maian Cube and then check in your PHP code that the relevant property exists.
More Reading
This tutorials briefly explains how you might set up a license property in ionCube. For a better understanding, please read the ionCube docs. If you are stuck, simply contact us for assistance. Thank you.