Looking to Build/Redesign a Website or Blog ?

To speak to Rakshit, call +91 968 704 2303

Delete Subdomain Dynamically Using PHP Script

Hello Friends,

In Last Post, I write about Create subdomain Dynamically Using PHP. Now once you create Subdomain Dynamically from PHP code, somewhere you are in need to delete that domain when you give option to manage websites under your user’s account. Delete Subdomain using PHP is as easy as Create Subdomain using PHP.

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";
$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)) {
// delete subdomain directory
$pass_shell = "rm -rf /home/" . $cpanel_username . "/public_html/" . $sub_domain_name;

$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.

Delete Subdomain using PHP Script, Delete Subdomain Dynamically, How to Delete Subdomain PHP Script, Delete Subdomain PHP Example, Delete Subdomain Hostgator PHP Script, Delete Subdomain Hostmosntor PHP Script, Delete Subdomain BlueHost PHP Script, Delete Subdomain Dynamically PHP Script


1 Comment

  • hi
    i have tried this but it’s not working in my case
    my subdomain is grabme ( grabme.shop2grab.com )
    and directory is

    plz help me
    thanks in advance

Leave a Reply

Your email address will not be published.