php网页病毒清除办法
发布:smiling 来源: PHP粉丝网 添加日期:2014-08-25 14:24:14 浏览: 评论:0
你的网页是不是经常被无故的在php,asp,html,js 等文件后台加上一些木马地址呢?我以前有个站就是这样,所以一恨之下写了这段代码,文章虽然有一点浪费资源了,但是总比我们手动清除要好吧,下面我为讲讲程序的清除病毒的原理吧.
首先们要读取 $checkFile 文件这个文章是判断一个文章 是否被感染了,如果是就会执行$savafile变量里面的txt文件路径的所有文件,进行按你infecFile病毒列表清除一次.
- <?php
 - Class clear_virus{
 - //public $content;
 - public $infectFile ='virus.txt';//病毒文件列表文件
 - public $savefile ="save.txt";//所在查看病毒的文件列表
 - public $timep ='time.txt';//些记录清除病毒时间
 - public $checkFile ='e.php';//这里是设置
 - 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'=>'病毒文件未不能读取!',
 - '2'=>'病毒文件列表不存在!',
 - '3'=>'文件列表不存了',
 - '4'=>'查杀的文件不存',
 - '5'=>$this->$checkFile.'不存在了,请设置病毒感染文件'
 - );//开源代码phpfensi.com
 - echo $array[$number];
 - }
 - }
 - $virus =new clear_virus;
 - $virus->open_file();
 - ?>
 
Tags: php网页病毒 php病毒清除
- 上一篇:php 表单敏感字符过滤代码
 - 下一篇:PHP文件页面缓存类
 
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
 - PHP新手上路(一)(7)
 - 惹恼程序员的十件事(5)
 - PHP邮件发送例子,已测试成功(5)
 - 致初学者:PHP比ASP优秀的七个理由(4)
 - PHP会被淘汰吗?(4)
 - PHP新手上路(四)(4)
 - 如何去学习PHP?(2)
 - 简单入门级php分页代码(2)
 - php中邮箱email 电话等格式的验证(2)
 
