Subdomain Dynamically Using PHP Script

3:50 AM

Hello Friends, Here is script to Delete Subdomain dynamically using PHP Script. It will delete sub domain and also delete subdomain director...


Hello Friends,
Here is script to Delete Subdomain dynamically using PHP Script. It will delete sub domain and also delete subdomain directory from your server.
function delete_subdomain($sub_domain_name,$cpanel_username,$cpanel_password,$main_domain) {
 
$build_request = "/frontend/x3/subdomain/dodeldomain.html?domain=". $sub_domain_name . "_" . $main_domain;
 
$open_socket = fsockopen('localhost',2082);
if(!$open_socket) {
return "Socket Error";
exit();
}
 
$auth_string = $cpanel_username . ":" . $cpanel_password;
$auth_pass = base64_encode($auth_string);
$build_headers = "GET " . $build_request ."\r\n";
$build_headers .= "HTTP/1.0\r\n";
$build_headers .= "Host:localhost\r\n";
$build_headers .= "Authorization: Basic " . $auth_pass . "\r\n";
$build_headers .= "\r\n";
 
fputs($open_socket, $build_headers);
while(!feof($open_socket)) {
fgets($open_socket,128);
}
fclose($open_socket);
 
// delete subdomain directory
$pass_shell = "rm -rf /home/" . $cpanel_username . "/public_html/" . $sub_domain_name;
system($pass_shell);
 
}
$sub_domain_name => Your Sub Domain Name Only. For e.g. mobile
$cpanel_username => Your Cpanel Username
$cpanel_password => Your Cpanel Password
$main_domain => Main Domain Name. For e.g. www.programmingfacts.com
So at the end, your subdomain http://mobile.programmingfacts.com will be deleted and “mobile” directory will also deleted from server.

No comments: