PHP code example of eliashaeussler / cpanel-requests
1. Go to this page and download the library: Download eliashaeussler/cpanel-requests library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
eliashaeussler / cpanel-requests example snippets
use EliasHaeussler\CpanelRequests\Application;
/** @var Application\Authorization\AuthorizationInterface $authorization */
$cPanel = new Application\CPanel($authorization, 'example.com', 2083);
use EliasHaeussler\CpanelRequests\Application;
/** @var Application\CPanel $cPanel */
$response = $cPanel->api('<module>', '<function>', ['optional' => 'parameters']);
if ($response->isValid()) {
// Do anything...
// Response data can be fetched using $response->getData()
}
use EliasHaeussler\CpanelRequests\Application;
use EliasHaeussler\CpanelRequests\Http;
$authorization = new Application\Authorization\TokenAuthorization(
username: 'bob',
token: '9CKU401OH5WVDGSAVXN3UMLT8BJ5IY',
);
$cPanel = new Application\CPanel(
authorization: $authorization,
host: 'cpanel.bobs.site',
port: 2083,
protocol: Http\Protocol::Https,
);
// Fetch domains from cPanel API
$response = $cPanel->api(
module: 'DomainInfo',
function: 'list_domains',
);
if (!$response->isValid()) {
throw new \RuntimeException('Got invalid response from cPanel application.');
}
$domains = $response->getData()->data;
echo 'Bob\'s main domain is: ' . $domains->main_domain;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.