I am trying to create subdomain dynamically using php. When user enters subdomain name in html form, a subdomain by that name should be created. I have got the script for that.
But when i run this, i get blank page, no directory is getting created. Somebody tell me where i am going wrong
php code is like this create.php
<?php
if(isset($_POST['subdomain_name']))
{
//$subDomain = $_POST['subdomain_name'];
function create_subdomain($subDomain,$cPanelUser,$cPanelPass,$rootDomain) {
echo $rootDomain;
$buildRequest = "/frontend/x3/subdomain/doadddomain.html?rootdomain=" . $rootDomain . "&domain=" . $subDomain . "&dir=public_html/subdomains/" . $subDomain;
$openSocket = fsockopen('localhost',2082);
if(!$openSocket) {
echo "error";
return "Socket error";
exit();
}
$authString = $cPanelUser . ":" . $cPanelPass;
$authPass = base64_encode($authString);
$buildHeaders = "GET " . $buildRequest ."\r\n";
$buildHeaders .= "HTTP/1.0\r\n";
$buildHeaders .= "Host:localhost\r\n";
$buildHeaders .= "Authorization: Basic " . $authPass . "\r\n";
$buildHeaders .= "\r\n";
fputs($openSocket, $buildHeaders);
echo $openSocket;
while(!feof($openSocket)) {
echo $opensocket;
fgets($openSocket,128);
}
fclose($openSocket);
$newDomain = "http://" . $subDomain . "." . $rootDomain . "/";
echo "new domain";
echo $newDomain;
// return "Created subdomain $newDomain";
}
$cpaneluser = "username";
$cpanelpass = "password";
$cpanel_skin = "x3";
$subd = $_POST['subdomain_name'];
$request = "/frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$domain&domain=$subd";
$result = create_subdomain($_POST['subdomain_name'],$cpaneluser,$cpanelpass,'ecommerce24.in');
$show = strip_tags($result);
if(strpos($show,"has been created!"))
{
echo "Subdomain Created!";
}
}
?>
my html form
<form action="create.php" method="post">
New Subdomain Name : <input name="subdomain_name" type="text" /><br />
<input type="submit" name="submit" value="Submit" />
</form>