-
-
Save khaidir/6cc098bc9f3cb2691b6837434830cf6b to your computer and use it in GitHub Desktop.
PHP Script to create subdomain on cpanel .
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function create_subdomain($subDomain,$cPanelUser,$cPanelPass,$rootDomain) { | |
// $buildRequest = "/frontend/x3/subdomain/doadddomain.html?rootdomain=" . $rootDomain . "&domain=" . $subDomain; | |
$buildRequest = "/frontend/x3/subdomain/doadddomain.html?rootdomain=" . $rootDomain . "&domain=" . $subDomain . "&dir=public_html/subdomains/" . $subDomain; | |
$openSocket = fsockopen('localhost',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:localhost\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"; | |
} | |
- See more at: http://vikku.info/programming/php/create-subdomain-dynamically-in-php-code-to-create-subdomains-in-server-using-php.htm#sthash.gg06VlWs.dpuf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function delete_subdomain($subDomain,$cPanelUser,$cPanelPass,$rootDomain) | |
{ | |
$buildRequest = "/frontend/x3/subdomain/dodeldomain.html?domain=" . $subDomain . "_" . $rootDomain; | |
$openSocket = fsockopen('localhost',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:localhost\r\n"; | |
$buildHeaders .= "Authorization: Basic " . $authPass . "\r\n"; | |
$buildHeaders .= "\r\n"; | |
fputs($openSocket, $buildHeaders); | |
while(!feof($openSocket)) { | |
fgets($openSocket,128); | |
} | |
fclose($openSocket); | |
$passToShell = "rm -rf /home/" . $cPanelUser . "/public_html/subdomains/" . $subDomain; | |
system($passToShell); | |
} | |
- See more at: http://vikku.info/programming/php/create-subdomain-dynamically-in-php-code-to-create-subdomains-in-server-using-php.htm#sthash.gg06VlWs.dpuf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment