NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page Add subdomain in cPanel via PHP

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search
7 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 02-19-2007, 10:34 PM THREAD STARTER               #1 (permalink)
AzN
is on hiatus
Join Date: May 2006
Posts: 2,449
AzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond repute
 


Find Marrow Donors! Ethan Allen Fund Ethan Allen Fund Ethan Allen Fund Save a Life Save a Life Save a Life Save a Life Save a Life Save a Life VA Tech Memorial VA Tech Memorial VA Tech Memorial VA Tech Memorial Save a Life Save a Life Save a Life

Add subdomain in cPanel via PHP


There was someone looking for this, so I took DeViAnThans3's script and modified it.
http://www.namepros.com/code/275464-...-creation.html


PHP Code:
  <?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($chCURLOPT_URL$url);
   
curl_setopt($chCURLOPT_HEADER1);
   
curl_setopt($chCURLOPT_USERAGENT$_SERVER['HTTP_USER_AGENT']);
   
curl_setopt($chCURLOPT_FOLLOWLOCATION1);
   
curl_setopt($chCURLOPT_RETURNTRANSFER1);
   
curl_setopt($chCURLOPT_COOKIEJAR'cookie.txt');
   
curl_setopt($chCURLOPT_COOKIEFILE'cookie.txt');
   if (
$method == 'POST') {
       
curl_setopt($chCURLOPT_POST1);
       
curl_setopt($chCURLOPT_POSTFIELDS$vars);
????: NamePros.com http://www.namepros.com/code/296341-add-subdomain-in-cpanel-via-php.html
   }
   
$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/");
????: NamePros.com http://www.namepros.com/showthread.php?t=296341

// 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
__________________
Currently on hiatus. Back whenever.
AzN is offline  
Old 02-19-2007, 10:39 PM   #2 (permalink)
Senior Member
 
RegisterRants's Avatar
Join Date: Oct 2006
Location: NJ
Posts: 1,147
RegisterRants has a spectacular aura aboutRegisterRants has a spectacular aura aboutRegisterRants has a spectacular aura about
 




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?
RegisterRants is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 03:32 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger