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 ADODB使用方法集锦
Mar 25 PHP
php中使用临时表查询数据的一个例子
Feb 03 PHP
PHP中对缓冲区的控制实现代码
Sep 29 PHP
使用gd库实现php服务端图片裁剪和生成缩略图功能分享
Dec 25 PHP
php带抄送和密件抄送的邮件发送方法
Mar 20 PHP
php数字每三位加逗号的功能函数
Oct 22 PHP
Smarty模板引擎缓存机制详解
May 23 PHP
windows server 2008/2012安装php iis7 mysql环境搭建教程
Jun 30 PHP
老生常谈PHP位运算的用途
Mar 12 PHP
phpStudy 2016 使用教程详解(支持PHP7)
Oct 18 PHP
php+ajax实现仿百度查询下拉内容功能示例
Oct 20 PHP
workerman结合laravel开发在线聊天应用的示例代码
Oct 30 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
JAVA/JSP学习系列之四
2006/10/09 PHP
说明的比较细的php 正则学习实例
2008/07/30 PHP
php学习笔记之 函数声明
2011/06/09 PHP
php数组函数序列之array_combine() - 数组合并函数使用说明
2011/10/29 PHP
php 检查电子邮件函数(自写)
2014/01/16 PHP
Yii中render和renderPartial的区别
2014/09/03 PHP
PHP中文竖排转换实现方法
2015/10/23 PHP
php + WebUploader实现图片批量上传功能
2019/05/06 PHP
use jscript with List Proxy Server Information
2007/06/11 Javascript
读jQuery之一(对象的组成)
2011/06/11 Javascript
jquery实现手机发送验证码的倒计时代码
2014/02/12 Javascript
jQuery中scrollLeft()方法用法实例
2015/01/16 Javascript
jQuery中extend函数详解
2015/07/13 Javascript
JS实现网页顶部向下滑出的全国城市切换导航效果
2015/08/22 Javascript
10个JavaScript中易犯小错误
2016/02/14 Javascript
微信小程序 实战实例开发流程详细介绍
2017/01/05 Javascript
vue+express+jwt持久化登录的方法
2019/06/14 Javascript
vue router 跳转时打开新页面的示例方法
2019/07/28 Javascript
python中查看变量内存地址的方法
2015/05/05 Python
Python cookbook(数据结构与算法)从任意长度的可迭代对象中分解元素操作示例
2018/02/13 Python
python斐波那契数列的计算方法
2018/09/27 Python
解决python多行注释引发缩进错误的问题
2019/08/23 Python
Python tkinter模版代码实例
2020/02/05 Python
OpenCV读取与写入图片的实现
2020/10/13 Python
基于HTML5超酷摄像头(HTML5 webcam)拍照功能实现代码
2012/12/13 HTML / CSS
男女时尚与复古风格在线购物:RoseGal(全球免费送货)
2017/07/19 全球购物
Java的接口和C++的虚类的相同和不同处
2014/03/27 面试题
一套Java笔试题
2016/08/20 面试题
什么是索引指示器
2012/08/20 面试题
Java的类可以定义为Protected或者Private得吗
2015/09/25 面试题
食品营养与检测应届生求职信
2013/11/08 职场文书
大学毕业感言100字
2014/02/03 职场文书
员工安全生产承诺书
2014/05/22 职场文书
高校群众路线教育实践活动剖析材料
2014/10/10 职场文书
win10+anaconda安装yolov5的方法及问题解决方案
2021/04/29 Python
mysql 直接拷贝data 目录下文件还原数据的实现
2021/07/25 MySQL