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进行MySQL删除记录操作代码
Jun 07 PHP
深入解析PHP垃圾回收机制对内存泄露的处理
Jun 14 PHP
使用PHP函数scandir排除特定目录
Jun 12 PHP
php实现编辑和保存文件的方法
Jul 20 PHP
php session 写入数据库
Feb 13 PHP
thinkphp3.x连接mysql数据库的方法(具体操作步骤)
May 19 PHP
Yii2中设置与获取别名的函数(setAlias和getAlias)用法分析
Jul 25 PHP
PHP 接入支付宝即时到账功能
Sep 18 PHP
利用php抓取蜘蛛爬虫痕迹的示例代码
Sep 30 PHP
thinkphp实现附件上传功能
May 26 PHP
PHP基于堆栈实现的高级计算器功能示例
Sep 15 PHP
laravel model模型定义实现开启自动管理时间created_at,updated_at
Oct 17 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
PHP调用Twitter的RSS的实现代码
2010/03/10 PHP
检测png图片是否完整的php代码
2010/09/06 PHP
执行、获取远程代码返回:file_get_contents 超时处理的问题详解
2013/06/25 PHP
PHP正则替换函数preg_replace和preg_replace_callback使用总结
2014/09/22 PHP
关于laravel5.5的定时任务详解(demo)
2019/10/23 PHP
我也种棵OO树JXTree[js+css+xml]
2007/04/02 Javascript
JavaScript将Table导出到Excel实现思路及代码
2013/03/13 Javascript
JS中setTimeout()的用法详解
2013/04/14 Javascript
Bootstrap基本组件学习笔记之导航(10)
2016/12/07 Javascript
浅谈DOM的操作以及性能优化问题-重绘重排
2017/01/08 Javascript
微信小程序之picker日期和时间选择器
2017/02/09 Javascript
vue 界面刷新数据被清除 localStorage的使用详解
2018/09/16 Javascript
微信小程序动画(Animation)的实现及执行步骤
2018/10/28 Javascript
使用Bootstrap做一个朝代历史表
2019/12/10 Javascript
使用原生javascript开发计算器实例代码
2021/02/21 Javascript
python新手经常遇到的17个错误分析
2014/07/30 Python
Python 实现文件的全备份和差异备份详解
2016/12/27 Python
简述:我为什么选择Python而不是Matlab和R语言
2017/11/14 Python
SVM基本概念及Python实现代码
2017/12/27 Python
微信跳一跳python代码实现
2018/01/05 Python
pip安装时ReadTimeoutError的解决方法
2018/06/12 Python
python2和python3在处理字符串上的区别详解
2019/05/29 Python
python是否适合网页编程详解
2019/10/04 Python
基于torch.where和布尔索引的速度比较
2020/01/02 Python
Html5在手机端调用相机的方法实现
2020/05/13 HTML / CSS
WoolOvers爱尔兰:羊绒、羊毛和棉针织品
2017/01/04 全球购物
英国的一家创新礼品和小工具零售商:Menkind
2019/08/24 全球购物
大学生通用个人的自我评价
2014/02/10 职场文书
幼儿园元旦活动感言
2014/03/02 职场文书
医药营销个人求职信
2014/04/12 职场文书
讲文明懂礼貌演讲稿
2014/09/11 职场文书
合法的离婚协议书范本
2014/10/23 职场文书
高中生打架检讨书1000字
2015/02/17 职场文书
大学生实习推荐信
2015/03/27 职场文书
2015年反腐倡廉工作总结
2015/05/14 职场文书
Jupyter Notebook内使用argparse报错的解决方案
2021/06/03 Python