Click here to Skip to main content
15,936,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a PHP script that will let you add a dynamic subdomain in cpanel from godaddy. But the problem is not adding a subdomain to the cpanel. Any advice or help will be much appreciated thank you.

What I have tried:

$whmusername = "sample";
$whmpassword = "@sample";
$subdomain = "mytestdomain";
$rootdomain = "";

$query = "https://".$rootdomain.":2087/json-api/cpanel?user=".$whmusername."&cpanel_jsonapi_module= SubDomain&cpanel_jsonapi_func=addsubdomain&cpanel_jsonapi_version=2&domain=".$subdomain."&rootdomain=".$rootdomain;

$curl = curl_init();

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);

curl_setopt($curl, CURLOPT_HEADER,0);

curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);

$header[0] = "Authorization: Basic " . base64_encode($whmusername.":".$whmpassword) . "\n\r";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_URL, $query);
$result = curl_exec($curl);
if ($result == false) { error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");

} curl_close($curl);

print $result;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900