Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Add subdomain in cPanel via PHP

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch
There was someone looking for this, so I took DeViAnThans3's script and modified it.
http://www.namepros.com/code/275464-automated-whm-account-creation.html


PHP:
  <?php
/* based on DeViAnThans3's whm script
no warranty is held for use of script  */  
 
/* HOW TO INSTALL
1 - Save this code as a PHP file (or any file, as long as the server recognizes it as PHP)
2 - Change the configuration part in this file, save it, and upload to your server
3 - Create an empty .txt file in notepad, call it cookie.txt, upload it to your server.
4 - Is your server a unix-like server? CHMOD that file to 777.
    This is not need for windows servers.
*/

// get domain info
$d = $_GET['d'];
$s = $_GET['s'];


// Configure
define("WHM_USER", "cpanel-username"); // cPanel username
define("WHM_PASS", "cpanel-pass"); // cPanel password
define("WHM_DOMAIN", "yourdomainhere");   // IP or hostname could be enterred here

// The new account settings!
// Go to line 75 in this file, and change everything to suit your needs.


// cURL class: Thanks to Sean Huber
class CURL {
   var $callback = false;

function setCallback($func_name) {
   $this->callback = $func_name;
}

function doRequest($method, $url, $vars) {
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_HEADER, 1);
   curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
   curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
   if ($method == 'POST') {
       curl_setopt($ch, CURLOPT_POST, 1);
       curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
   }
   $data = curl_exec($ch);
   curl_close($ch);
   if ($data) {
       if ($this->callback)
       {
           $callback = $this->callback;
           $this->callback = false;
           return call_user_func($callback, $data);
       } else {
           return $data;
       }
   } else {
       return curl_error($ch);
   }
}

function get($url) {
   return $this->doRequest('GET', $url, 'NULL');
}

function post($url, $vars) {
   return $this->doRequest('POST', $url, $vars);
}
}

// Initialize cURL library
$curl = new CURL;

$text = $curl->get("http://" . WHM_USER . ":" . WHM_PASS . "@" . WHM_DOMAIN .":2082/");

// Create account now
// First going to this form; required, else wont work
$text = $curl->get("http://" . WHM_USER . ":" . WHM_PASS . "@" . WHM_DOMAIN .":2082/frontend/x2/subdomain/doadddomain.html?");

// Fine! Set the options now. refer to original post on usage guide
$options = "domain=".$s."&rootdomain=".$d."";

// And post it!
$text = $curl->post("http://" . WHM_USER . ":" . WHM_PASS . "@" . WHM_DOMAIN .":2082/frontend/x2/subdomain/doadddomain.html?", $options);

// Eventually you can output the text here
echo $text;
?>

No warranty provided for script usage.
No copyright or licensing required.

Simply call the php file with ?d=(your main domain)&s=(subdomain wanted)
Ex: .php?d=namepros.com&s=chat
This will set up chat.namepros.com
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Yeah, I was looking for this ;)

The problem is that I do not want to install cURL on my server...all the c99 stuff that's out there, ya know?
 
0
•••
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back