Development Guides Home >> Quickstart Development Guide
Tutorial - Create a New cPanel Interface in PHP
Introduction
This tutorial uses PHP to create a new cPanel interface. The examples below use the Jupiter theme's master template, which creates new interfaces that integrate seamlessly with the appearance of the main cPanel interface.
- To create a new cPanel interface in Template Toolkit, read our Create a New cPanel Interface tutorial.
- To create a new WHM interface in PHP, read our Create a New WHM Interface in PHP tutorial.
Create a PHP file and connect to the LiveAPI system
To begin, create a new PHP file. This file must use the .live.php
file extension.
The example below:
- Instantiates the CPANEL object, which ensures that the file uses the LiveAPI PHP class .
- Uses the LiveAPI new() method to connect to cPanel & WHM.
- Uses the LiveAPI end() method to disconnect from cPanel & WHM.
<?php
include("/usr/local/cpanel/php/cpanel.php"); // Instantiate the CPANEL object.
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
?>
<?php
$cpanel->end(); // Disconnect from cPanel - only do this once.
?>
Add Jupiter's header and footer
Use the header()
and footer()
methods to add Jupiter's header and footer to the interface.
The example below:
- Uses the LiveAPI header() method to add Jupiter's header to the top of the interface, and set Page Heading as the page title.
- Uses the LiveAPI footer() method to add Jupiter's footer to the bottom of the interface.
<?php
include("/usr/local/cpanel/php/cpanel.php"); // Instantiate the CPANEL object.
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
print $cpanel->header( "Page Heading , app_key" ); // Add the header.
?>
<?php
print $cpanel->footer(); // Add the footer.
$cpanel->end(); // Disconnect from cPanel - only do this once.
?>
Add a UAPI function
The LiveAPI uapi()
method calls UAPI functions.
The example below:
-
Uses LiveAPI's
uapi()
method to call UAPI'sDomainInfo::domains_data
function.
<?php
include("/usr/local/cpanel/php/cpanel.php"); // Instantiate the CPANEL object.
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
print $cpanel->header( "Page Heading" ); // Add the header.
?>
<?php
$get_userdata = $cpanel->uapi( // Get domain user data.
'DomainInfo', 'domains_data',
array(
'format' => 'hash',
)
);
?>
<?php
print $cpanel->footer(); // Add the footer.
$cpanel->end(); // Disconnect from cPanel - only do this once.
?>