3

我的代码执行良好,但未创建文件夹和子域。请告诉我到底在哪里做错了。

function create_subdomain($subDomain,$cPanelUser,$cPanelPass,$rootDomain)
{
    $buildRequest = "/frontend/x3/subdomain/doadddomain.html?rootdomain=" . $rootDomain . "&domain=" . $subDomain . "&dir=public_html/subdomains/" . $subDomain;

    $openSocket = fsockopen('78.46.111.226',2082);
    if(!$openSocket) {
        return "Socket error";
        exit();
    }

    $authString = $cPanelUser . ":" . $cPanelPass;
    $authPass = base64_encode($authString);
    $buildHeaders  = "GET " . $buildRequest ."\r\n";
    $buildHeaders .= "HTTP/1.0\r\n";
    $buildHeaders .= "Host:$rootDomain\r\n";

    $buildHeaders .= "Authorization: Basic " . $authPass . "\r\n";
    $buildHeaders .= "\r\n";

    fputs($openSocket, $buildHeaders);
    while(!feof($openSocket)) {
    fgets($openSocket,128);
    }
    fclose($openSocket);

    $newDomain = "http://" . $subDomain . "." . $rootDomain . "/";

    return "Created subdomain $newDomain";

}

希望尽快回复提前谢谢。

4

2 回答 2

2

为什么你需要为此创建动态文件夹,你可以使用 htaccess 面糊。

尝试以下相同的 htaccess 代码:

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com *.example.com
    DocumentRoot /www/domain
</VirtualHost>
于 2013-11-12T08:39:24.327 回答
-1

代替

$openSocket = fsockopen('78.46.111.226',2082);

$openSocket = fsockopen('localhost',2082);

并更换

$buildHeaders .= "Host:$rootDomain\r\n";

$buildHeaders .= "Host:localhost\r\n";
于 2015-06-09T12:45:57.710 回答