cPanelLicensing PHP Class


Last modified: March 12, 2021

Overview

The cPanelLicensing PHP class runs Manage2 API functions. You can use this to manage customer licenses from the command line or through the Manage2 user interface.

Important:
  • The cPanelLicensing PHP class requires PHP 5 with cURL and SimpleXML support. PHP 5 enables SimpleXML support by default.
  • SimpleXML transforms XML into data structures that are similar to associative arrays.
  • The cPanelLicensing PHP class returns SimpleXML objects by default, or can return XML, JSON, or YAML.

Download the module

To download the cPanelLicensing PHP class, click the cPanel License Management API SDK link in the Automation menu on the Manage2 Dashboard interface.

Basic use

The following script uses the cPanelLicensing PHP class to call the Manage2 List License Information function:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// Include the cPanelLicensing class.
include("cpl.inc.php");
  
// Instantiate the cPanelLicensing object.
$cpl = new cPanelLicensing($USERNAME, $PASSWORD);
 
// Combine the parameters into an array.
$args = array("ip" => "192.0.2.0");
  
// Call the desired function with the parameters as an argument.
$cpl->fetchLicenses($args);

Include the cPanelLicensing class

Line 2 uses PHP’s include() statement to include and evaluate the cPanelLicensing class:

1
2
// Include the cPanelLicensing class
include("cpl.inc.php");

Instantiate the cPanelLicensing object

Line 4 instantiates the cPanelLicensing object, which provides the script with access to the cPanelLicensing object’s functions:

4
5
// Instantiate the cPanelLicensing object.
$cpl = new cPanelLicensing(username, password);
Note:

Include the following variables when you instantiate the cPanelLicensing object:

  • username — The user’s username.
  • password — The user’s password.

Call a function

Line 8 defines an array of the function’s input parameters. Line 11 calls the Manage2 List License Information function and passes the array as an argument:

7
8
9
10
11
// Combine the function's parameters into an array.
$args = array("ip" => "192.0.2.0");
  
// Call the Fetch License function.
$cpl->fetchLicenses($args); 

You can also perform this action in one step:

7
8
9
10
// Call the Fetch License function with the input parameters directly.
$cpl->fetchLicenses( array(
    "ip" => "192.0.2.0"
);

Methods

The cPanelLicensing PHP class includes the following methods:

The set_format method

Use the set_format method to choose the PHP class’s output type. By default, the class returns a SimpleXML object.

$cpl->set_format("json");

The set_format method accepts a single parameter with one of the following string values:

  • simplexml — Return SimpleXML.
  • xml — Return XML.
  • json — Return JSON.
  • yaml — Return YAML.

The findKey method

Note:

This method only operates in SimpleXML mode.

Use the findKey method to retrieve a group or package name.

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

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

Additional Documentation