在php中创建动态子域名

时间:2014-07-10 09:57:27

标签: php subdomain

使用以下代码我尝试创建动态子域。

<?php
//Set the name for your New Sub Domain
$subDomainname="testdomain";

//cPanel Username
$cPanelUserName="user";

//cPanel Password
$cPanelPassName="pass";

//Main Domain Name
$rootDomainName="example.com";


//Function to create subdomain
function create_subdomain($subDomain,$cPanelUser,$cPanelPass,$rootDomain) {

//Generate URL for access the subdomain creation in cPanel through PHP

$buildRequest = "frontend/x3/subdomain/doadddomain.html?domain=testdomain&rootdomain=example.com&dir=public_html%2Ftest";
//Open the socket
$openSocket = fsockopen('localhost',2083);
if(!$openSocket) {
    //SHow error
    return "Socket error";
    exit();
}


//Login Details
$authString = $cPanelUser . ":" . $cPanelPass;

//Encrypt the Login Details 
$authPass = base64_encode($authString);

//Request to Server using GET method
$buildHeaders  = "GET " . $buildRequest ."\r\n";

//HTTP
$buildHeaders .= "HTTP/1.0\r\n";
//Define Host
$buildHeaders .= "Host:localhost\r\n";

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

//fputs
fputs($openSocket, $buildHeaders);

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

//Return the New SUbdomain with full URL
$newDomain = "http://" . $subDomain . "." . $rootDomain . "/";

//return with Message
return "Created subdomain $newDomain";

}
//Call the subdomain creator function
echo create_subdomain($subDomainname,$cPanelUserName,$cPanelPassName,$rootDomainName);

&GT;

输出:

显示&#34;创建子域testdomain.example.com&#34;

但仍然访问了这个无效的网址。

cpanel子域列表中没有添加任何内容。

我错了!帮助我。

是否需要为服务器授予权限?

0 个答案:

没有答案