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 相关文章推荐
php下过滤html代码的函数 提高程序安全性
Mar 02 PHP
使用PHP会话(Session)实现用户登陆功能
Jun 29 PHP
浅析Mysql 数据回滚错误的解决方法
Aug 05 PHP
PHP基于imap获取邮件实例
Nov 11 PHP
php使用指定字符列表生成随机字符串的方法
Apr 18 PHP
PHP常见的6个错误提示及解决方法
Jul 07 PHP
ThinkPHP和UCenter接口冲突的解决方法
Jul 25 PHP
php fread读取文件注意事项
Sep 24 PHP
Laravel Memcached缓存驱动的配置与应用方法分析
Oct 08 PHP
基于ThinkPHP实现的日历功能实例详解
Apr 15 PHP
PHP魔术方法之__call与__callStatic使用方法
Jul 23 PHP
YII框架模块化处理操作示例
Apr 26 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
jq的get传参数在utf-8中乱码问题的解决php版
2008/07/23 PHP
apache+php完美解决301重定向的两种方法
2011/06/08 PHP
php把字符串指定字符分割成数组的方法
2018/03/12 PHP
lnmp安装多版本PHP共存的方法详解
2018/08/02 PHP
thinkphp框架表单数组实现图片批量上传功能示例
2020/04/04 PHP
jQuery实现等比例缩放大图片让大图片自适应页面布局
2013/10/16 Javascript
使用jquery自定义鼠标样式满足个性需求
2013/11/05 Javascript
js修改原型的属性使用介绍
2014/01/26 Javascript
jQuery实现级联菜单效果(仿淘宝首页菜单动画)
2014/04/10 Javascript
jquery插件EasyUI中form表单提交实例分享
2016/01/11 Javascript
TypeOf这些知识点你了解吗
2016/02/21 Javascript
js时间戳格式化成日期格式的多种方法介绍
2017/02/16 Javascript
BootstrapTable refresh 方法使用实例简单介绍
2017/02/20 Javascript
vue2.0 实现页面导航提示引导的方法
2018/03/13 Javascript
vue动画之点击按钮往上渐渐显示出来的实例
2018/09/29 Javascript
微信小程序实现发送验证码按钮效果
2018/12/20 Javascript
详解Vue+ElementUI从零开始搭建自己的网站(一、环境搭建)
2019/04/30 Javascript
解决vue单页面修改样式无法覆盖问题
2019/08/05 Javascript
vue3.0中使用postcss-pxtorem的具体方法
2019/11/20 Javascript
JavaScript自定义超时API代码实例
2020/04/30 Javascript
Python学习之Django的管理界面代码示例
2018/02/10 Python
Django开发的简易留言板案例详解
2018/12/04 Python
Python中numpy模块常见用法demo实例小结
2019/03/16 Python
pygame实现非图片按钮效果
2019/10/29 Python
matplotlib.pyplot画图并导出保存的实例
2019/12/07 Python
python 如何上传包到pypi
2020/12/24 Python
一款纯css3实现的竖形二级导航的实例教程
2014/12/11 HTML / CSS
使用html2canvas实现将html内容写入到canvas中生成图片
2020/01/03 HTML / CSS
Java里面如何把一个Array数组转换成Collection, List
2013/07/26 面试题
品质管理部岗位职责范文
2014/03/01 职场文书
优秀工会工作者事迹材料
2014/06/02 职场文书
装修施工安全责任书
2014/07/24 职场文书
岗位说明书怎么写
2014/07/30 职场文书
2014年重阳节老干部座谈会上的讲话稿
2014/09/25 职场文书
千与千寻观后感
2015/06/04 职场文书
漫改真人电影「萌系男友是燃燃的橘色」公开先导视觉图
2022/03/21 日漫