Adding subdomain using PHP script?

rjgapz

Registered
Nov 12, 2018
1
0
1
philippines
cPanel Access Level
Website Owner
Can you please help me on how to add a dynamic subdomain to the cpanel of godaddy. Any idea why is it not working? Here is the php script.
Code:
<?
$whmusername = "sample";
$whmpassword = "sample";
$subdomain = "mytestdomain";
$rootdomain = "sample";

$query = "https://".$rootdomain.".com:2083/cpsess2971083704/json-api/cpanel?cpanel_jsonapi_user=".$whmusername."&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=SubDomain&cpanel_jsonapi_func=addsubdomain&domain=".$subdomain."&rootdomain=".$rootdomain."&dir=%2Fpublic_html%2Fdirectory_name&disallowdot=1";

$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;
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,237
463
Hello @rjgapz,

Can you let us know the error message that appears in /usr/local/cpanel/logs/error_log when running the script or the error that's displayed in your browser or command line upon executing the script?

Thank you.