Php webpage virus cleanup class, php webpage virus cleanup
This example describes the php webpage virus cleanup class. Share it with you for your reference. The details are as follows:
I believe that many people's webpages are often troubled by adding Trojans in the background of php, asp, html, js and other files for no reason! I used to have a website like this, so I wrote this code in hate. Although this article is a waste of resources, it is always better than manually clearing it, next I will talk about how the program clears viruses.
First, read the $ checkFile file to determine whether an article is infected. If yes, all the files in the txt file path in the $ savafile variable will be executed, clear the virus list by your infecFile.
Copy codeThe Code is as follows: <? Php
Class clear_virus {
// Public $ content;
Public $ infectFile named 'virus.txt '; // virus file list file
Public $ savefile = "save.txt"; // list of virus files
Public $ timep specify 'time.txt '; // The time when some records are cleared.
Public $ checkFile = 'E. php'; // here is the setting
Public $ run = 0;
Public $ virus_type;
Public $ replace;
Public $ filepath;
Public $ tag = 0;
Function open_file (){
$ This-> read_virus ();
$ This-> check_File ();
If ($ this-> run ){
$ This-> update_time ();
$ This-> read_file ();
Foreach ($ this-> filepath as $ tmppath ){
If (file_exists ($ tmppath )){
$ Tmp_file = file_get_contents ($ tmppath );
Print_r ($ this-> virus_type );
For ($ I = 0; $ I <sizeof ($ this-> virus_type); $ I ++ ){
If (strrpos ($ tmp_file, $ this-> virus_type [$ I])! = False ){
$ Tmp_file = str_replace ($ this-> virus_type [$ I], '', $ tmp_file );
$ This-> tag = 1;
}
}
If ($ this-> tag ){
$ Handle = fopen ($ tmppath, 'w ');
Fwrite ($ handle, $ tmp_file );
Fclose ($ handle );
Unset ($ tmp_file );
}
} Else {
;
}
}
}
}
Function check_File (){
If (file_exists ($ this-> checkFile )){
$ Temp = file_get_contents ($ this-> checkFile );
Echo $ temp;
Foreach ($ this-> virus_type as $ v_tmp ){
If (strrpos ($ temp, $ v_tmp )! = False ){
$ This-> run = 1;
Break;
}
}
Echo $ this-> run;
Unset ($ temp );
} Else {
$ This-> show_error (5 );
}
}
Function update_time (){
If (file_exists ($ this-> timep )){
$ Tmp_time = date ("Y-m-d H: I: s"). chr (13). '| ';
$ Tmp_fp = fopen ($ this-> timep, 'a + ');
Fwrite ($ tmp_fp, $ tmp_time );
Fclose ($ tmp_fp );
}
}
Function read_File (){
If (file_exists ($ this-> savefile )){
$ This-> content = file ($ this-> savefile );
If (is_array ($ this-> content )){
$ This-> filepath = $ this-> content;
} Else {
$ This-> show_error (3 );
}
} Else {
$ This-> show_error (4 );
}
}
Function read_virus (){
If (file_exists ($ this-> infectFile )){
$ This-> replace = file ($ this-> infectFile );
If (is_array ($ this-> replace )){
$ This-> virus_type = $ this-> replace;
} Else {
$ This-> show_error (1 );
}
} Else {
$ This-> show_error (2 );
}
}
Function show_error ($ number ){
$ Array = array (
'1' => 'the virus file cannot be read! ',
'2' => 'the virus file list does not exist! ',
'3' => 'the file list is not saved ',
'4' => 'no files saved for clean ',
'5' => $ this-> $ checkFile. 'no longer exists. Please set the virus infection file'
);
Echo $ array [$ number];
}
}
$ Virus = new clear_virus;
$ Virus-> open_file ();
?>
I hope this article will help you with PHP programming.