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.

PHP class for adding Subdomain

Discussion in 'cPanel Developers' started by Sillysoft, Jun 5, 2009.

  1. Sillysoft

    Sillysoft Member

    Joined:
    Jun 5, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    New here, I am trying to find a way to allow a logged in user to dynamically add a subdomain using cpanel api. I saw an earlier post with example code using php to add the subdomain using the XMLAPI calls. I was wondering since I am on php4 is there a php4 wrapper class for this?
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Since PHP 4 is EOL'd by The PHP Group, we do not have a PHP 4 wrapper class.

    However, I did post some PHP 4-compatible code to the forums for accessing the XML API calls a while ago:

    http://forums.cpanel.net/322538-post6.html

    It's not as convenient as having a PHP class, but it'll give you a good start to creating your own wrapper class for PHP 4 if you desire.
     
  3. Sillysoft

    Sillysoft Member

    Joined:
    Jun 5, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Thanks for the response! I got it to work! My last question is say someone wanted to create a subdomain off an existing domain or create a whole new domain. How could I dynamically tell if the domain they entered is a subdomain or a new domain? Is there a call in the api to get the list of current domains in cpanel so I can check against it to determine which api call to use?

    What Im trying to do is just have a field where the person enters a domain, either a sub domain or a full domain, and in the backend the code calls the cpanel api to create an addon domain for a new domain not in the system or a subdomain if the domain is already in the system.
     
  4. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    The raw API1 function call for adding a subdomain is:

    Code:
    <cpanel SubDomain="addsubdomain(domain, rootdomain,0,0,dir)">
    domain is the subdomain to add (e.g. something in something.example.com)

    rootdomain is the domain the subdomain should be added to (e.g. example.com for something.example.com)

    dir is the path, relative to the user's home directory, where files should be served from when this subdomain is requested (e.g. public_html/dir, subdomains/dir etc.)

    To list all subdomains on an account, use this API2 function:

    Code:
    <?cp SubDomain::listsubdomains() ?>
    This function does take an optional regex parameter if you wish to do a Perl regular expression to find a specific subdomain to see if it exists on the account.

    Documentation for creating an addon domain using API2 is available at:

    Api2AddonDomains < AllDocumentation/AutomationIntegration < TWiki

    The API2 function for listing addon domains is:

    HTML:
    <?cp Park::listaddondomains() ?>
    This function also takes an optional regex parameter that works just like the one for subdomains.
     
Loading...

Share This Page