Source Guardian Product Setup - External License File

Overview
This is a brief tutorial on how to set up a product in Source Guardian to use an external license file. For a better understanding of this you should consult your Source Guardian documentation. Note that this tutorial assumes the Windows GUI version of Source Guardian.

We would recommend you get used to Source Guardian first before attempting to use Maian Guardian. A better understanding of Source Guardian will make this software easier to use.
1 Add product/project to Source Guardian
Firstly, you need to add your product to Source Guardian. Select "Create New Project" from the main screen and browse for folder on hard drive and add on the source screen:


Click the "Advanced" tab to view / create project key and ID.


Note that the project key and ID entered here will be the same as the ones you enter when setting up a product in Maian Guardian.
2 Lock - External License File
Next, click the "Lock" button and view the "Lock to a license file" option at the top:


Check box and enter a license file name in the box provided:


Note that the license name you enter here will be the same as the one you enter when setting up a product in Maian Guardian.
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 when you enter the license file name. Click to create license file in your project folder:

4 License Custom Defined Constants
When creating a license file, it's a good idea to have some constants in place so that you can perform various checks in your software. 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 Source Guardian constants come in.

In the Source Guardian documentation, section 4.26 has information relating to "Custom predefined constants", so lets look at this in more detail.
5 License Custom Defined Constants - Loader API
The Source Guardian Loader contains a built in API providing various functions and constants (please refer to the Source Guardian docs, section 4.2.6) that may be useful in PHP scripts. The function we are interested in is the "sg_get_const()" function.

This function returns the value of file constants that were added to the encoded file with the Encoder --const option. Only constants defined in the calling script or license file are available. So, you can hard code the constants via the Source Guardian encoder OR create them on the fly via the licgen program.
6 License Custom Defined Constants - Add Constants to License in Source Guardian
Lets add two constants, one via the encoder and one via Maian Guardian. Both with different values.

Via Encoder

Click the "Lock" button again and add a custom predefined constant. Let's add a constant called 'versiontype' and the value is 'free'.


Via Maian Guardian

Enter via "Constants" tab for any product. Let's add a constant called 'versiontype' and the value is 'commercial'.


So, initially, when the license file is created via the encoder, a constant called 'versiontype' will have the value 'free'. When a new license is generated via Maian Guardian, the constant value of 'versiontype' will change to 'commercial'.

NOTE that constants are case sensitive!
7 License Custom Defined Constants - Constant Checking via Loader API
Ok, so now our license file contains the constant 'versiontype'. We can check for this in our PHP file via the Source Guardian "sg_get_const()" loader API function. If the constant exists and it's value is 'free', it's the free version. If it exists and it's value is 'commercial', it's the commercial version. Here is a code example.

NOTE: This check would take place inside an encoded PHP file.

<?php

$sg_const = (function_exists('sg_get_const') ? sg_get_const('versiontype') : '');
if (in_array($sg_const, array('free','commercial'))) {
  switch($sg_const) {
    case 'free':
      // free version - do appropriate action
      break;
    case 'commercial':
      // commercial version - do appropriate action or other checks
      break;
  }
} else {
  // invalid..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 constant and do an appropriate action. You can have as many constants as you need and you can determine how best to use them.

Do testing in Source Guardian and Maian Guardian to get a feel for how things work.
8 License Custom Defined Constants - Constants Reminder
When you set up your product in Maian Guardian, you enter the constant values that will be included in the new license file when it is downloaded by a visitor. The above example just touches on the possibilities.

When your script/software checks the constant values in the license it should always be via an encoded file, so it can't be tampered with.

Finally, you don't have to add constants in the Source Guardian interface. You can just add them in Maian Guardian and then check in your PHP code that the relevant constant exists.
More Reading
This tutorials briefly explains how you might set up a license in Source Guardian to use an external license file. For a better understanding, please read the Source Guardian docs. If you are stuck, simply contact us for assistance or Source Guardian if your issue is with their software. Thank you.