Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    478
    Thanks
    7
    Thanked 3 Times in 3 Posts

    using PHP to create sub-domains in cpanel

    I am wanting to know if it is possible to create sub-domains using PHP ?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    It is always possible. Probably not directly with PHP though, none of the included extensions jump out as handling networking and domain settings. You could check PECL, otherwise, its simply command line calls with PHP.
    CPanel wise, check the cpanel documentation to see if they have an api that includes this functionality.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Posts
    462
    Thanks
    0
    Thanked 20 Times in 20 Posts
    Yep! I havn't had the time to test out their code yet but you could try it and let me know!?

    PHP Code:
    function
    create_subdomain($subDomain,$cPanelUser,$cPanelPass,$rootDomain) {
    //Generate URL for access the subdomain creation in cPanel through PHP
    $buildRequest "/frontend/x3/subdomain/doadddomain.html?rootdomain=" .
    $rootDomain "&domain=" $subDomain .
    "&dir=public_html/subdomains/" $subDomain

    //Open the socket
    $openSocket fsockopen('localhost',2082); if(!$openSocket) { 

    //SHow error 
    return "Socket error"; exit(); } 

    //Login Details 
    $authString $cPanelUser ":" $cPanelPass

    //Encrypt the Login Details
    $authPass base64_encode($authString);

     
    //Request to Server using GET method
    $buildHeaders "GET " $buildRequest ."\r\n"

    //HTTP
    $buildHeaders .= "HTTP/1.0\r\n";

    //Define Host
    $buildHeaders .= "Host:localhost\r\n";

    //Request Authorization
    $buildHeaders .= "Authorization: Basic " $authPass "\r\n"$buildHeaders .= "\r\n"

    //fputs 
    fputs($openSocket,$buildHeaders); while(!feof($openSocket)) { fgets($openSocket,128); }
    fclose($openSocket); 

    //Return the New SUbdomain with full URL
    $newDomain "http://" $subDomain "." $rootDomain "/";

    //return with Message
    return "Created subdomain".$newDomain;
    }


    //Call the subdomain creator function
    echo create_subdomain($subDomainname,$cPanelUserName,$cPanelPassName,$rootDomainName); 
    Found it @ How to create subdomains using PHP. Couldn't find a script or function that would remove them dynamically. So we're pretty much on our own unless one of the pros wouldn't mind making one.

    Let me know if it works!
    Thanks.
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    For projects using MediaTypes (MIMETypes) visit E-BAM.net -(updated weekly)

    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •