php中的动态子域创建
使用下面的代码,我尝试创建动态子域php中的动态子域创建,php,subdomain,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 cr
<?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);
?>
输出:
它显示创建的子域testdomain.example.com
但仍然访问了该url,但该url不起作用
在cpanel子域列表中没有添加任何内容。
我哪里做错了!!帮帮我
是否需要为服务器授予权限?我不能100%确定这一点,但在“创建子域”页面上是否有防止CSRF的令牌?如果是这样的话,您需要找到一种方法来生成它们,但是这并没有显示安全令牌的任何错误