Home > PHP > PHP – Create subdomain using CPanel

PHP – Create subdomain using CPanel

I needed to create a script that would login to cpanel and create subdomains. It also creates a new folder for the user.

The following script does just this:

<?php
// your cPanel username
$cpanel_user = '<username>';
// your cPanel password
$cpanel_pass = '<password>';
// your cPanel skin
$cpanel_skin = 'x3';
// your cPanel domain
$cpanel_host = '<domain name>';
// subdomain name
$subdomain = '<subdomain name>';
// create the subdomain
$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\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);
}
fclose($sock);
echo $result;
?>

Advertisements
  1. September 27, 2011 at 6:44 AM

    New season sale! WebHosting, Dedicated Server, VPS e more with free Domain Name registration! Visit us at realhosting.me

  2. December 6, 2012 at 12:37 PM

    I’m not that much of a online reader to be honest but your sites really nice, keep it up!
    I’ll go ahead and bookmark your website to come back later. Cheers

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: