Forum Moderators: coopster
- 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
Put this in a file call addsubdomain.php
<?phpini_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 :)