Forum Moderators: coopster

Message Too Old, No Replies

subdomain creating

         

gate2vn

2:37 am on Mar 6, 2004 (gmt 0)



Is there any script helping me to create subdomain automatically by the following way?

- create a form for clients fill out username, password
- when they submit form, the script will create a subdomain for them with their username

I can do it manually in CPanel or HELM.... but I want to do automatically with my form. Pls help. Thanks

lorax

4:18 pm on Mar 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld gate2vn
What you're asking for might exist in an OTS package - but I'm not sure. I know I've seen it but I can't say for sure if it was a custom script or not.

Elijah

5:03 pm on Mar 6, 2004 (gmt 0)

10+ Year Member



A while ago I found the same kind of thing that you are looking for. I don't remember where I got the code from so I'll just post the code here.
Here is the source of the files that work for me.
You will need to change: $host, $cpaneluser, and $cpanelpass.
You might also need to change $path.

Put this in a file call addsubdomain.php


<?php

ini_set('display_errors', 1);

$host = "YOURDOMAIN.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 = "YOURUSERNAME";
$cpanelpass = "YOURPASSWORD";
$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.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Authorization: Basic $pass \r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($poststring)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $poststring . "\r\n\r\n");

//*************************************
// 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);
}
print "Subdomain ".$_POST['subdomain'].'Created go to :<a href="http://'.$_POST['subdomain'].'.'.$host.'/">http://'.$_POST['subdomain'].'.'.$host.'</a>';
?>

Then put this in a file called index.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>

Now just go to index.php and enter the name of the subdomian that you want to create.
As for password protecting this script you could either just protect the whole directory or add in a user system. That's up to you.

I'm sure this code can be refined etc.. ;)

I hope this works for you. If not please post back and I'll try to help.

Elijah :)