The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Create subdomains using php?! And a few other stuff

Discussion in 'cPanel Developers' started by alexsimi80, Aug 23, 2010.

  1. alexsimi80

    alexsimi80 Registered

    Joined:
    Aug 23, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Hello,

    I am a newbie in cPanel's API so I really need help to do something. So, I have to make 3 things when someone creates an account to my website:
    1. Create a subdomain like subdomain.mydomain.com
    2. Create an e-mail address for the subdomain - office@name.subdomain.mydomain.com
    3. Create a database.

    I have to make all this in a php script, so I think I must use API but I tryed to learn something about it and it is to hard for me for the moment.
    So, could someone just give me some examples of how to do any/all of those 3 actions?

    Regards,
    Laurentiu
     
  2. alexsimi80

    alexsimi80 Registered

    Joined:
    Aug 23, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    I found a sollutin but it's not working.
    The code is this:
    Code:
    $login = "user";
    $pass = "pass";
    $domain = "domain.com";
    $output = fopen ("http://$login:$pass@www.$domain:2082/frontend/x3/subdomain/doadddomain.html?domain=$subdomain&rootdomain=$domain&go=Create", "r");
    print ("Subdomain Created.<br>\n");
    
    The code works but with no effect :(. If I try to paste the link "http://$login:$pass@www.$domain:2082/frontend/x3/subdomain/doadddomain.html?domain=$subdomain&rootdomain=$domain&go=Create" in the browser, it creates a subdomain, but if I run that script it doesn't.
    What am I doing wrong?

    Later edit: If I try to print $output, the result is: Resource id #3
     
    #2 alexsimi80, Aug 23, 2010
    Last edited: Aug 23, 2010
  3. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi Laurentiu,

    You should take a look at the XMLAPI PHP client class. It's let's you programmatically code PHP to perform WHM/cPanel tasks against the XMLAPI interface. There are native XMLAPI functions, used for tasks normally performed in WHM, and you can make cPanel API requests too (like the ones you mentioned).

    You can download it here, http://sdk.cpanel.net/lib/xmlapi/php/cp_xmlapi_php_v1.0.6.tar.gz
    The tarball has some examples. You should search around the forums, there's lots of examples of how to use it proficiently. Also, there's the Integration Blog which has some posts that use it too.

    Let me know if you have any specific questions.
    Best Regards,
    -DavidN
     
Loading...

Share This Page