跟我学小偷程序教程之小偷原理(第二天)

有个朋友说的好,其实教功夫也是变相的教你怎么杀人,可是不说出来.
所以这个教程从下一篇开始就改个名字
叫<远程操作对方数据程序>有点土比小偷好听
第二天.
教几个函数给大家.
1 读取判断函数
2 更新cache函数
3 写入文件函数
4 切割字符函数
5 读取字符函数
---------------------------------------------------
在我们想写之前我们先要做好准备,构思一下怎么去写.
[color=Red]制作前构思1[/color]
我们打开华军首页
[url]http://www.onlinedown.net/[/url]
经过我们统计,是不是发现它的连接有个很相同的规则?
1 根目录的index.htm文件
2 soft文件夹的 1.htm .......30000.htm
3 sort文件夹的 1_1.htm 200_1.htm
4 a-z文件夹 1.htm ....200.htm
到此我们可以想好一个打开函数,不是根目录 就是文件夹/名字
只有2中可能.
[color=Red]制作前构思2[/color]
为了让速度更快,我们最好把内容读过来存储起来.
1 减少了对对方站点的请求.
2 提供了速度.
这里我们判断这个文件写入的时间为准 我们自己设置一个时间
当写入时间 和现在的时间比一下,如果在我们的设置时间内的话.就是可以.
如果不在比如
文件写入时间 2004年5月18好 06:00 我们现在时间是2004年5月19号 18:00
我们设置时间是1个小时
当再次请求这个文件的时候 他发现已经过期了.就会重新向对方请求一次并且存入.
[color=Red]制作前构思3[/color]
为了以后频繁的操作简单话,把固定的操作写进一个函数.
切割字符.
一般切割就是 从第一个位置 切割到第二个位置 然后取中间部分
比如:
[color=Black]

1<html>
2<head>
3<title>演示站点</title>
4</head>
5<body>
6</body>
7</html>

[/color]

1<title>开始切割到</title>

那切割出来的 就是 "演示站点"4个字
如果说,可以找到 几个

  1<title>怎么办?程序会从第一处开始切割   
  2到这里构思差不多..   
  3程序要干净明了才行,不要这一个文件不知道什么,那一个文件不知道哪来.   
  4所以,如果你以后有做大站的机会的话,文件夹,文件一定要写的清楚,分的清楚.   
  5既然明白了构思,我们就开始动手做了.   
  6建立我们第一个PHP文件:   
  7你可以用记事本,可以用Dreamweaver也可以用专用PHP编辑软件   
  8取名字为 commom.php   
  9内容为   
 10\------------------------   
 11[color=Red]```
 12   
 13include './config.php';   
 14include './global.php';   
 15
 16```[/color]-----------------------   
 17这个文件有什么用?就是在以后操作中直接 inclue 这个文件就可以用到所有的函数啊什么的   
 18然后config.php是设置 URL 刷新时间 等等   
 19global.php是 所有函数的文件   
 20也就是今天要给教给大家的!   
 21第一个个函数 open   
 22\-------------   
 23[color=ff0000]function open( $file, $type=''){   
 24global $fromurl, $referer;   
 25$cachename= $file;   
 26if( $type){   
 27$file= $fromurl.'/'. $type.'/'. $file;   
 28}else{   
 29$file= $fromurl. $file;   
 30}   
 31  
 32  
 33  
 34  
 35if( $open=file( $file)){   
 36$count=count( $open);   
 37for( $i=0; $i&lt; $count; $i++){   
 38$theget.= $open[ $i];   
 39  
 40}   
 41  
 42}else{   
 43die('请求过多,超时,请刷新');   
 44}   
 45  
 46  
 47return $theget;   
 48  
 49}[/color]   
 50\----------------   
 51[color=Blue]解释过了,连接地址就2中请求,根目录,和 文件夹/名字[/color]   
 52函数怎么用法等等,不多说了.建议大家下载译本PHP中文手册看看.   
 53第二个函数   
 54根据设置时间更新cache目录文件函数 update   
 55\---------------   
 56[color=Red]function update( $file, $type=''){   
 57global $timestamp, $flush;   
 58if(!file_exists("cache/ $file")){   
 59if( $type){   
 60$data=open( $file, $type);   
 61}else{   
 62$data=open( $file);   
 63}   
 64  
 65writetofile("cache/ $file", $data);   
 66}else{   
 67$lastflesh=@filemtime("cache/ $file");   
 68  
 69  
 70  
 71if( $lastflesh + ( $flush * 60) &lt; $timestamp ){   
 72if( $type){   
 73$data=open( $file, $type);   
 74}else{   
 75$data=open( $file);   
 76}   
 77writetofile("cache/ $file", $data);   
 78}   
 79}   
 80  
 81}[/color]   
 82\--------   
 83简单解释   
 84[color=Blue] $data=open( $file, $type);[/color]就是用到上面的 open函数了   
 85如果我们用 udate("index.htm");   
 86那不就是用到了 update函数吗? 明白吗?   
 87上面出现了writetofile函数 下面是代码   
 88\------------------------------   
 89[color=Red]function writetofile( $file_name, $data, $method="w") {   
 90if( $filenum=fopen( $file_name, $method)){   
 91flock( $filenum,LOCK_EX);   
 92$file_data=fwrite( $filenum, $data);   
 93fclose( $filenum);   
 94return $file_data;   
 95}else{   
 96return false;   
 97}   
 98}[/color]---------------------------------   
 99切割字符函数   
100\------------------------   
101[color=ff0000]function cut( $file, $from, $end){   
102  
103$message=explode( $from, $file);   
104$message=explode( $end, $message[1]);   
105return $message[0];   
106}[/color]   
107\----------------------------   
108读取函数   
109\---------------------   
110[color=Red]function readfromfile( $file_name) {   
111if( $filenum=fopen( $file_name,"r")){   
112flock( $filenum,LOCK_SH);   
113$file_data=fread( $filenum,filesize( $file_name));   
114fclose( $filenum);   
115return $file_data;   
116}else{   
117return false;   
118}   
119  
120}[/color]   
121\-------------------------------------   
122把所有函数写成一个文件 保存起来 取名字叫 global.php   
123内容如下:   
124\------------------------------------------------------------------------------------------------   
125[color=Blue]```
126   
127function open( $file, $type=''){   
128global $fromurl, $referer;   
129$cachename= $file;   
130if( $type){   
131$file= $fromurl.'/'. $type.'/'. $file;   
132}else{   
133$file= $fromurl. $file;   
134}   
135  
136  
137  
138  
139if( $open=file( $file)){   
140$count=count( $open);   
141for( $i=0; $i&amp;lt; $count; $i++){   
142$theget.= $open[ $i];   
143  
144}   
145  
146}else{   
147die('请求过多,超时,请刷新');   
148}   
149  
150  
151return $theget;   
152  
153}   
154  
155function update( $file, $type=''){   
156//更新cache中的文件   
157global $timestamp, $flush;   
158if(!file_exists("cache/ $file")){   
159if( $type){   
160$data=open( $file, $type);   
161}else{   
162$data=open( $file);   
163}   
164  
165writetofile("cache/ $file", $data);   
166}else{   
167$lastflesh=@filemtime("cache/ $file");   
168  
169  
170  
171if( $lastflesh + ( $flush * 60) &amp;lt; $timestamp ){   
172if( $type){   
173$data=open( $file, $type);   
174}else{   
175$data=open( $file);   
176}   
177writetofile("cache/ $file", $data);   
178}   
179}   
180  
181}   
182function readfromfile( $file_name) {   
183if( $filenum=fopen( $file_name,"r")){   
184flock( $filenum,LOCK_SH);   
185$file_data=fread( $filenum,filesize( $file_name));   
186fclose( $filenum);   
187return $file_data;   
188}else{   
189return false;   
190}   
191  
192}   
193  
194  
195function writetofile( $file_name, $data, $method="w") {   
196if( $filenum=fopen( $file_name, $method)){   
197flock( $filenum,LOCK_EX);   
198$file_data=fwrite( $filenum, $data);   
199fclose( $filenum);   
200return $file_data;   
201}else{   
202return false;   
203}   
204}   
205function cut( $file, $from, $end){   
206  
207$message=explode( $from, $file);   
208$message=explode( $end, $message[1]);   
209return $message[0];   
210}   
211function updatecache( $file, $cache=''){   
212global $timestamp, $flush;   
213if(!file_exists( $file)){   
214writetofile( $file, $cache);   
215$return= $cache;   
216}elseif(@filemtime( $file) &amp;lt; $timestamp - ( $flush * 60)){   
217writetofile( $file, $cache);   
218$return= $cache;   
219}else{   
220$return=readfromfile( $file);   
221}   
222return $return;   
223}   
224
225```[/color]   
226\-----------------------------------------------------------------------------------------------------   
227其中有几个变量在config.php中设置一下   
228我们建立config.php文件 内容如下:   

$fromurl = "http://www.onlinedown.net/";
$flush="120";//update函数中自动同步更新时间

 1\------------------------   
 2现在位置我们有了3个文件了 commom.php config.php global.php   
 3有了3个文件 程序总体完成了.接下来如何去偷呢?   
 4心急的人可以先试试   
 5建立一个index.php文件 就是首页   
 6你先做好模板 的样子   
 7HTML先做好.   
 8然后在   
 9<html>   
10........   
11........   
12</html>   
13的上方插入PHP代码   
14如下:   

require './commom.php';
update("index.htm");
$file=readfromfile("cache/index.htm");
$gwrj = cut( $file,"<td height='"118"' width='"307"'>","</td>");

 1<html>   
 2.......   
 3......   
 4.......   
 5</html>   
 6在你想要插入的地方插入[color=Red]```
 7 echo $gwrj; 
 8```[/color]   
 9就是从首页中切割出来的国外软件   
10自己试试   
11今天就到这里!   
12[size=4][color=ff0000]下一个接教如何读取分类页面.和简单介绍PHP模板技术的原理.再下节讲模板,不需要HTML中出现PHP代码了.分离开来[/color][/size]   
13  
14[[i] Last edited by tomkity on 2004-5-20 at 19:05 [/i]]</title>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus