Create subdomains using PHP?


subdomainform.php

<html>
<head>
<title>create a subdomain</title>
</head>
<body>
<form name “form1” method “post” action “addsubdomain.php”>
<h1>create Sub Domains</h1>
Sub Domain Name : <input type “text” name “subdomain”><br />
<input type “submit” name “Submit” value “Submit”>
</form>
</body>
</html>

addsubdomain.php

<?php

ini_set(‘display_errors’ 1);

$host “domainname.com”; // your domain name without the www
$port 2082;
$path “/frontend/x/subdomain/doadddomain.html?domain “.$_POST[‘subdomain’].”&rootdomain “.$host; //or .dll etc. for authnet etc.

// these lines are changed
$cpaneluser “username”;
$cpanelpass “pass”;
$authstr “$cpaneluser:$cpanelpass”;
//****************************

// Setup the Auth String
$pass base64_encode($authstr);

$fp fsockopen($host $port $errno $errstr $timeout 30);

if(!$fp){
//error tell us
echo “$errstr ($errno)n”;

}else{

//send the server request

fputs($fp “POST $path HTTP/1.1rn”);
fputs($fp “Host: $hostrn”);
fputs($fp “Authorization: Basic $pass rn”);
fputs($fp “Content-type: application/x-www-form-urlencodedrn”);
fputs($fp “Content-length: “.strlen($poststring).”rn”);
fputs($fp “Connection: closernrn”);
fputs($fp $poststring . “rnrn”);

//*************************************
// Remove this to stop it from displaying the output fron the CPanel
//*************************************
//loop through the response from the server
/*
while(!feof($fp)) {
echo fgets($fp 4096);
}

*/
while(!feof($fp)) { fgets($fp 4096); }
//close fp – we are done with it
fclose($fp);
}

*****************************

  1. In you main httpd.conf add the following line at the bottom:Include /path/to/subdomains.conf

file name subdomains.conf

@mkdir ( /path/to/subdirectory/ .$name );

  1. $vhost
  2. ServerAdmin yourname@yourserver.com
  3. DocumentRoot /path/to/subdirectory/ .$name.
  4. ServerName .$name. .yourserver.com
  5. ErrorLog /path/to/logs/ .$name. _error_log
  6. ;
  7. $fo fopen ( /path/to/subdomains.conf a );
  8. $fw fwrite ( $fo $vhost );
  9. fclose ( $fo );

******************************

Bookmark and Share
Advertisements
  1. November 22nd, 2009
    Trackback from : Trackback

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: