0

我正在尝试使用 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> 
4

1 回答 1

1

尝试将其放在脚本的 biginning 中:

error_reporting (E_ALL | E_STRICT);
ini_set ('display_errors', '-1');

它可能会使 php 向您显示一条错误消息,从而导致解决方案。

于 2012-09-29T14:16:31.927 回答