Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Adding subdomain using PHP script?

Discussion in 'cPanel Developers' started by rjgapz, Nov 12, 2018.

Tags:
  1. rjgapz

    rjgapz Registered

    Joined:
    Nov 12, 2018
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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;
    
    
     
    #1 rjgapz, Nov 12, 2018
    Last edited by a moderator: Nov 13, 2018
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    47,002
    Likes Received:
    2,123
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice