我正在尝试使用 php 动态创建子域。当用户以 html 形式输入子域名时,应创建一个该名称的子域。我有那个脚本。
但是当我运行它时,我得到空白页,没有创建目录。有人告诉我哪里出错了
php 代码是这样的 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!";
}
}
?>
我的html表单
<form action="create.php" method="post">
New Subdomain Name : <input name="subdomain_name" type="text" /><br />
<input type="submit" name="submit" value="Submit" />
</form>