Skip to main content

Creating Subdomains using PHP

Comments

5 comments

  • cPanelMichael
    Hello, Documentation on API authentication is available at: Guide to API Authentication - Software Development Kit - cPanel Documentation Could you provide us with the contents of the PHP script you are using to create the subdomain? Thank you.
    0
  • Dan Ashbridge
    Hello, the PHP is below:
    $cpanel_user = 'REMOVED'; $cpanel_pass = 'REMOVED'; $cpanel_skin = 'paper_lantern'; $cpanel_host = 'REMOVED'; $dir = 'public_html/'; $sock = fsockopen($cpanel_host, 2082); if(!$sock) { print('Socket error'); exit(); } $pass = base64_encode("$cpanel_user:$cpanel_pass"); $in = "GET /frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$cpanel_host&domain=$subdomain&dir=$dir\r\n"; $in .= "HTTP/1.0\r\n"; $in .= "Host:$cpanel_host\r\n"; $in .= "Authorization: Basic $pass\r\n"; $in .= "\r\n"; fputs($sock, $in); while (!feof($sock)) { $result .= fgets ($sock, 128); } echo $result;
    0
  • cPanelMichael
    Hello, The example you provided does not appear to authenticate properly due to lack of a session ID. You should consider using the following cPanel API 2 function and PHP client class to develop the PHP script: cPanel API 2 Functions - SubDomain::addsubdomain - Software Development Kit - cPanel Documentation GitHub - CpanelInc/xmlapi-php: A PHP Class for Interacting with cPanel's XML-API Thank you.
    0
  • pradipkp
    Hello, Could you please assist me to solve the issue I have a website. Hosted on linux shared need to create automatic subdomains on user registration based on username entered in registration form The hosting allows unlimited subdomains I would like someone to assist me
    0
  • cPRex Jurassic Moderator
    @pradipkp - just as the earlier posters in this thread, you would need to create a custom solution using the cPanel API that integrates with your server and website. There isn't a ready-made code example that will perform this work for you.
    0

Please sign in to leave a comment.