Website Self Destruct from Browser Bar

i would not recommend that as a solution,
why don’t you secure the script instead ?

anyway just for the fun of it here is a function that will delete a folder

function deleteAll($directory, $empty = false) {
    $t= time(); // you can also use it to delete old files by subtracting from this

    if(substr($directory,-1) == "https://stackoverflow.com/") {
        $directory = substr($directory,0,-1);
    }

    if(!file_exists($directory) || !is_dir($directory)) {
        return false;
    } elseif(!is_readable($directory)) {
        return false;
    } else {
        $directoryHandle = opendir($directory);

        while ($contents = readdir($directoryHandle)) {
            if($contents != '.' && $contents != '..') {
                if(filemtime($directory . "https://stackoverflow.com/" . $contents) < $t) {
                    $path = $directory . "https://stackoverflow.com/" . $contents;

                    if(is_dir($path)) {
                        @deleteAll($path);
                    } else {
                        @unlink($path);
                    }
                }
            }
        }

        closedir($directoryHandle);
        if($empty == false) {
            if(!@rmdir($directory)) {
                return false;
            }
        }

        return true;
    }
}

(!) be careful when you use it it will DELETE everything you can call it like this deleteAll(".", true);

but this is not a solution look into securing your script

Leave a Comment