Using the cPanel Licensing PHP Class

The PHP cPanelLicensing class simplifies development of automated cPanel License provisioning. You can download this class from your Manage2 interface.

Download the cPanel Licensing PHP class
Download the cPanel Licensing PHP class from your Manage2 interface.

This class requires PHP5 with curl support and SimpleXML support (which is on by default). This class returns SimpleXML objects by default; however, it can be configured to return XML, JSON, or YAML.

note Note: SimpleXML is a feature of PHP5 that allows XML to easily be transformed into data structures similar to associative arrays.

Using the class

In order to use the cPanelLicensing PHP class, you will need to include the file and create the object like any normal object in PHP:

include("cpl.inc.php");
$cpl = new cPanelLicensing(__USERNAME__, __PASSWORD__);

At this point, you are ready to call a function inside of the class. Each function uses named parameters, meaning that it has to be passed an associative array containing the URL parameters inside of it:

$args = array( "ip" => "192.168.1.1" );
$cpl->fetchLicense($args);

Alternatively, this can be done inline:

$cpl->fetchLicense( array(
	"ip" => "192.168.1.1"
);

Special functions

The cPanelLicensing PHP class contains a few convenience functions designed to make working with the class much easier.

set_format

set_format allows one to choose what output type the PHP class will give. By default, this will return a SimpleXML object, but this class is capable of returning raw XML, JSON or YAML. This function takes a single parameter, which must be any of the following strings:

  • simplexml
  • xml
  • json
  • yaml

It is called like the following:

$cpl->set_format("json");

findKey

findKey allows you to look up Package or Group IDs by name, and returns the ID.

This function will only operate when the class is operating inside of SimpleXML mode.

This function accepts two parameters: search and package SimpleXML objects.

$packages = $cpl->fetchPackages();
$packageid = $cpl->findKey("ONE-YEAR", $packages);

Topic revision: r11 - 04 Apr 2011 - 17:50:03 - MelanieSeibert
ManageTwo.UsingPHPClasses moved from Sandbox.UsingPHPClasses on 21 Jul 2009 - 19:08 by Main.JustinSchaefer - put it back