Creating Licenses from PHP
While Padlock doesn't offer a direct method of generating licenses from PHP, it's straightforward to have a PHP script execute the Padlock console utilities to achieve the desired functionality. Below is a sample script that shows how to create a license from PHP, with the only prerequisites being a Padlock install, Java, and a pre-generated KeyPair file.
Basic license generation
// KeyPair file, this should be in the same folder as the PHP script. // For production, this file *really* needs to be in a folder not readable via HTTP. $key = "test.key"; // The generated license file, which will be in the same folder as the script. $licenseFile = "$test.lic"; // Actually generate the license. This assumes Padlock and its files are all in ./padlock exec ("$java -jar padlock/LicenseMaker.jar -k $key -o $licenseFile");
The above code creates a very basic (and somewhat useless) license called test.lic. To take this a step further and add some properties, simply add the -p flag:
License generation with properties
// KeyPair file, this should be in the same folder as the PHP script. // For production, this file *really* needs to be in a folder not readable via HTTP. $key = "test.key"; // The generated license file, which will be in the same folder as the script. $licenseFile = "$test.lic"; // Add two properties, Name and Email. $props = "\"name=John Smith, email=john@smithcorp.com\""; // Actually generate the license. This assumes Padlock and its files are all in ./padlock exec ("$java -jar padlock/LicenseMaker.jar -k $key -o $licenseFile -p $props");