php网页病毒清除类


Posted in PHP onDecember 08, 2014

本文实例讲述了php网页病毒清除类。分享给大家供大家参考。具体如下:

相信很多人的网页经常被无故的在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.'不存在了,请设置病毒感染文件' 

   );

   echo $array[$number]; 

  } 

     

 } 

 $virus =new clear_virus; 

 $virus->open_file(); 

?>

希望本文所述对大家的PHP程序设计有所帮助。

PHP 相关文章推荐
安装APACHE
Jan 15 PHP
一些使用频率比较高的php函数
Oct 03 PHP
php 方便水印和缩略图的图形类
May 21 PHP
用Php编写注册后Email激活验证的实例代码
Mar 11 PHP
深入php self与$this的详解
Jun 08 PHP
php获取客户端电脑屏幕参数的方法
Jan 09 PHP
Java中final关键字详解
Aug 10 PHP
Apache启动报错No space left on device: AH00023该怎么解决
Oct 16 PHP
PHP XML Expat解析器知识点总结
Feb 15 PHP
laravel5.1框架基础之Blade模板继承简单使用方法分析
Sep 05 PHP
phpinfo的知识点总结
Oct 10 PHP
TP5框架实现签到功能的方法分析
Apr 05 PHP
ThinkPHP入口文件设置及相关注意事项分析
Dec 05 #PHP
简单实用的PHP防注入类实例
Dec 05 #PHP
ThinkPHP连接数据库的方式汇总
Dec 05 #PHP
PHP生成RSS文件类实例
Dec 05 #PHP
php实现两表合并成新表并且有序排列的方法
Dec 05 #PHP
ThinkPHP中redirect用法分析
Dec 05 #PHP
php查询ip所在地的方法
Dec 05 #PHP
You might like
ajax php传递和接收变量实现思路及代码
2012/12/19 PHP
无需重新编译php加入ftp扩展的解决方法
2013/02/07 PHP
Windows2003下php5.4安装配置教程(IIS)
2016/06/30 PHP
PHP弱类型语言中类型判断操作实例详解
2017/08/10 PHP
PHP操作Redis常用技巧总结
2018/04/24 PHP
PHP如何使用JWT做Api接口身份认证的实现
2020/02/03 PHP
基于Jquery的动态添加控件并取值的实现代码
2010/09/24 Javascript
在图片上显示左右箭头类似翻页的代码
2013/03/04 Javascript
jQuery中json对象的复制方式介绍(数组及对象)
2013/06/08 Javascript
IE6 hack for js 集锦
2014/09/23 Javascript
jquery ui bootstrap 实现自定义风格
2014/11/14 Javascript
详解AngularJS实现表单验证
2015/12/10 Javascript
完美的js div拖拽实例代码
2016/09/24 Javascript
简单理解vue中track-by属性
2016/10/26 Javascript
JS检测数组类型的方法小结
2017/03/14 Javascript
使用html+js+css 实现页面轮播图效果(实例讲解)
2017/09/21 Javascript
JavaScript中concat复制数组方法浅析
2019/01/20 Javascript
JavaScript动画实例之粒子文本的实现方法详解
2020/07/28 Javascript
[02:41]DOTA2英雄基础教程 冥魂大帝
2014/01/16 DOTA
详解Python的迭代器、生成器以及相关的itertools包
2015/04/02 Python
Python使用poplib模块和smtplib模块收发电子邮件的教程
2016/07/02 Python
Python使用sftp实现上传和下载功能(实例代码)
2017/03/14 Python
Python3使用正则表达式爬取内涵段子示例
2018/04/22 Python
python实现维吉尼亚算法
2019/03/20 Python
python deque模块简单使用代码实例
2020/03/12 Python
Python基于read(size)方法读取超大文件
2020/03/12 Python
Python使用文件操作实现一个XX信息管理系统的示例
2020/07/02 Python
浅谈h5自定义audio(问题及解决)
2016/08/19 HTML / CSS
Spartoo美国:欧洲排名第一的在线时装零售商
2019/12/12 全球购物
办理信用卡工作证明
2014/01/11 职场文书
干部培训自我鉴定
2014/01/22 职场文书
幼儿园六一儿童节主持节目串词
2014/03/21 职场文书
关于梦想的演讲稿
2014/05/05 职场文书
捐助贫困学生倡议书
2014/05/16 职场文书
欢迎领导标语
2014/06/27 职场文书
投标承诺函格式
2015/01/21 职场文书