nescafeboy1 发表于 2015-8-29 11:11:09

今天所学到的PHP网页小偷(偷华军哦)

  做PHP也一些时间了,以前都是基本上写企业程序.今天张哥给我出一韪目,就是偷取小日本网页上的内容...
今天看了大半天,现在终于写好了全站代码:废话少说..大家看吧.不是吹的哦..
  commom.php 文件:
  <?php
include './config.php';
include './global.php';
?>
  config.php 文件:
  <?php
$fromurl = "http://www.newhua.com/";
$flush="120";//update函数中自动同步更新时间
?>
  global.php 文件(主要函数)
  <?php
function open($file,$type=''){
         global $fromurl,$referer;
         $cachename=$file;
               if($type){
                         $file=$fromurl.'/'.$type.'/'.$file;
               }else{
                         $file=$fromurl.$file;
               }
  
               
               
                         if($open=file($file)){
                                       $count=count($open);
                                       for($i=0;$i<$count;$i++){
                                                 $theget.=$open[$i];
  }
                                       
                                 }else{
                                       die('请求过多,超时,请刷新');
                                 }
               
               
         return $theget;
  }
  function update($file,$type=''){
//更新cache中的文件
         global $timestamp,$flush;
         if(!file_exists("cache/$file")){
               if($type){
                         $data=open($file,$type);
               }else{
                         $data=open($file);
               }
               
               writetofile("cache/$file",$data);
         }else{
               $lastflesh=@filemtime("cache/$file");
               
      
      
               if($lastflesh + ($flush * 60) < $timestamp ){
                         if($type){
                                 $data=open($file,$type);
                         }else{
                                 $data=open($file);
                         }
                         writetofile("cache/$file",$data);
               }
         }
  }
function readfromfile($file_name) {
         if($filenum=fopen($file_name,"r")){
               flock($filenum,LOCK_SH);
               $file_data=fread($filenum,filesize($file_name));
               fclose($filenum);
               return $file_data;
         }else{
               return false;
         }
      
}
  
function writetofile($file_name,$data,$method="w") {
         if($filenum=fopen($file_name,$method)){
               flock($filenum,LOCK_EX);
               $file_data=fwrite($filenum,$data);
               fclose($filenum);
               return $file_data;
         }else{
               return false;
         }
}
function cut($file,$from,$end){
  $message=explode($from,$file);
         $message=explode($end,$message);
return         $message;
}
function updatecache($file,$cache=''){
         global $timestamp,$flush;
         if(!file_exists($file)){
               writetofile($file,$cache);
               $return=$cache;
         }elseif(@filemtime($file) < $timestamp - ($flush * 60)){
               writetofile($file,$cache);
               $return=$cache;
         }else{
               $return=readfromfile($file);      
         }
         return $return;
}
?>
  index.php 文件用于...不用说了吧?
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?
require './commom.php';
update("index.htm");
$file=readfromfile("cache/index.htm");
$gnrj = cut($file,"<td valign=top bgcolor=#ffffff class=fontline10 colspan=2>","<td valign=top align=center width=290>");
///gnrj 定义下面的调用内容.
///<td valign=top bgcolor=#ffffff class=fontline10 colspan=2>取目标页面中的后面部分.
///<td valign=top align=center width=290>取目标页面中的前面部分.
$gnrj = str_replace("soft/","soft.php?id=",$gnrj);
$gnrj = str_replace(".htm","",$gnrj);
//就是把偷过来的国外软件中的代码更换.
//原来的
//<a target=_blank href="soft/18204.htm">
//变为了现在的
//<a target=_blank href="soft.php?id=18204">
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>华军PHP小偷</title>
</head>
  <body>
<table width="416" height="187" border="1" align="center">
<tr>
    <td>华军国内软件</td>
</tr>
<tr>
    <td><? echo $gnrj; ///调用数据?></td>
</tr>
</table>
</body>
</html>
页: [1]
查看完整版本: 今天所学到的PHP网页小偷(偷华军哦)