🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
**php网页病毒清除办法** 你的网页是不是经常被无故的在php,asp,html,js 等文件后台加上一些木马地址呢?我以前有个站就是这样,所以一恨之下写了这段代码,文章虽然有一点浪费资源了,但是总比我们手动清除要好吧,下面我为讲讲程序的清除病毒的原理吧. 首先们要读取 $checkFile 文件这个文章是判断一个文章 是否被感染了,如果是就会执行$savafile变量里面的txt文件路径的所有文件,进行按你infecFile病毒列表清除一次. ``` > 1. <?php  > 2.  Class clear\_virus{  > 3.   //public $content; > 4.   public$infectFile ='virus.txt';//病毒文件列表文件 > 5.   public$savefile    ="save.txt";//所在查看病毒的文件列表 > 6.   public$timep  ='time.txt';//些记录清除病毒时间 > 7.   public$checkFile ='e.php';//这里是设置 > 8.   public$run   =0;  > 9.   public$virus\_type;  > 10.   public$replace  ;  > 11.   public$filepath ;   > 12.   public$tag         =0;   > > 14.   function open\_file(){  > 15.    $this\->read\_virus();     > 16.    $this\->check\_File();  > 17.    if($this\->run){   > 18.     $this\->update\_time();   > 19.     $this\->read\_file() ;      > 20.     foreach($this\->filepath as$tmppath){  > 21.      if(file\_exists($tmppath)){  > 22.       $tmp\_file =file\_get\_contents($tmppath);   > 23.       print\_r( $this\->virus\_type);        > 24.         for( $i\=0;$ivirus\_type);$i++ ){  > 25.          if( strrpos($tmp\_file,$this\->virus\_type\[$i\])!== false){  > 26.           $tmp\_file =str\_replace($this\->virus\_type\[$i\],'',$tmp\_file);  > 27.           $this\->tag =1;            > 28.          }           > 29.         }  > 30.         if( $this\->tag ){  > 31.          $handle =fopen($tmppath,'w');  > 32.          fwrite($handle,$tmp\_file);  > 33.          fclose($handle);  > 34.          unset($tmp\_file);   > 35.         }       > > 37.      }else{  > 38.       ;  > 39.      }        > 40.     }   > 41.    }  > 42.   }  > > 44.   function check\_File(){  > 45.    if(file\_exists($this\->checkFile) ){  > 46.     $temp =file\_get\_contents($this\->checkFile) ;  > 47.     echo$temp;  > 48.      foreach( $this\->virus\_type as$v\_tmp ){  > 49.       if( strrpos($temp,$v\_tmp)!== false ){  > 50.        $this\->run =1;  > 51.        break;  > 52.       }  > 53.      }  > 54.      echo$this\->run;  > 55.      unset($temp);      > 56.    }else{  > 57.     $this\->show\_error(5);  > 58.    }  > 59.   }  > > 61.   function update\_time(){  > 62.    if(file\_exists($this\->timep) ){  > 63.     $tmp\_time =date("Y-m-d H:i:s").chr(13).'|';  > 64.     $tmp\_fp  =fopen($this\->timep,'a+');  > 65.     fwrite($tmp\_fp,$tmp\_time);  > 66.     fclose($tmp\_fp);      > 67.    }  > > 69.   }  > > 72.   function read\_File(){    > 73.    if(file\_exists($this\->savefile) ){     > 74.     $this\->content =file($this\->savefile);      > 75.     if(is\_array($this\->content)){      > 76.      $this\->filepath =$this\->content;       > 77.     }else{  > 78.      $this\->show\_error(3);  > 79.     }  > 80.    }else{  > 81.     $this\->show\_error(4);  > 82.    }   > 83.   }  > > 86.   function read\_virus(){    > 87.    if(file\_exists($this\->infectFile) ){     > 88.     $this\->replace =file($this\->infectFile);      > 89.     if(is\_array($this\->replace)){      > 90.      $this\->virus\_type=$this\->replace;       > 91.     }else{  > 92.      $this\->show\_error(1);  > 93.     }  > 94.    }else{  > 95.     $this\->show\_error(2);  > 96.    }   > 97.   }  > > 100.   function show\_error($number){  > 101.    $array = array(  > 102.     '1'\=>'病毒文件未不能读取!',  > 103.     '2'\=>'病毒文件列表不存在!',  > 104.     '3'\=>'文件列表不存了',  > 105.     '4'\=>'查杀的文件不存',  > 106.     '5'\=>$this\->$checkFile.'不存在了,请设置病毒感染文件' > 107.    );//开源代码phpfensi.com > 108.    echo$array\[$number\];  > 109.   }  > > 111.  }  > 112.  $virus =new clear\_virus;  > 113.  $virus\->open\_file();  > 114. ?> ```