第一天的教程连接地址
http://www.vipcn.com/infoview/article_3751.html
今天教第二天.
有个朋友说的好,其实教功夫也是变相的教你怎么杀人,可是不说出来.
所以这个教程从下一篇开始就改个名字
叫<远程操作对方数据程序>有点土比小偷好听
第二天.
教几个函数给大家.
1 读取判断函数
2 更新cache函数
3 写入文件函数
4 切割字符函数
5 读取字符函数
---------------------------------------------------
在我们想写之前我们先要做好准备,构思一下怎么去写.
制作前构思1
我们打开华军首页
http://www.onlinedown.net/
经过我们统计,是不是发现它的连接有个很相同的规则?
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中可能.
制作前构思2
为了让速度更快,我们最好把内容读过来存储起来.
1 减少了对对方站点的请求.
2 提供了速度.
这里我们判断这个文件写入的时间为准 我们自己设置一个时间
当写入时间 和现在的时间比一下,如果在我们的设置时间内的话.就是可以.
如果不在比如
文件写入时间 2004年5月18好 06:00 我们现在时间是2004年5月19号 18:00
我们设置时间是1个小时
当再次请求这个文件的时候 他发现已经过期了.就会重新向对方请求一次并且存入.
制作前构思3
为了以后频繁的操作简单话,把固定的操作写进一个函数.
切割字符.
一般切割就是 从第一个位置 切割到第二个位置 然后取中间部分
比如:
<html>
<head>
<title>演示站点</title>
</head>
<body>
</body>
</html>
从<title>开始切割到</title>
那切割出来的 就是 "演示站点"4个字
如果说,可以找到 几个 <title>怎么办?程序会从第一处开始切割
到这里构思差不多..
程序要干净明了才行,不要这一个文件不知道什么,那一个文件不知道哪来.
所以,如果你以后有做大站的机会的话,文件夹,文件一定要写的清楚,分的清楚.
既然明白了构思,我们就开始动手做了.
建立我们第一个php文件:
你可以用记事本,可以用dreamweaver也可以用专用php编辑软件
取名字为 commom.php
内容为
------------------------
<?php
include './config.php';
include './global.php';
?>-----------------------
这个文件有什么用?就是在以后操作中直接 inclue 这个文件就可以用到所有的函数啊什么的
然后config.php是设置 url 刷新时间 等等
global.php是 所有函数的文件
也就是今天要给教给大家的!
第一个个函数 open
-------------
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;
}
----------------
解释过了,连接地址就2中请求,根目录,和 文件夹/名字
函数怎么用法等等,不多说了.建议大家下载译本php中文手册看看.
第二个函数
根据设置时间更新cache目录文件函数 update
---------------
function update($file,$type=''){
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);
}
}
}
--------
简单解释
$data=open($file,$type);就是用到上面的 open函数了
如果我们用 udate("index.htm");
那不就是用到了 update函数吗? 明白吗?
上面出现了writetofile函数 下面是代码
------------------------------
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[1]);
return $message[0];
}
----------------------------
读取函数
---------------------
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;
}
}
-------------------------------------
把所有函数写成一个文件 保存起来 取名字叫 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[1]);
return $message[0];
}
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;
}
?>
-----------------------------------------------------------------------------------------------------
其中有几个变量在config.php中设置一下
我们建立config.php文件 内容如下:
<?php
$fromurl = "http://www.onlinedown.net/";
$flush="120";//update函数中自动同步更新时间
?>
------------------------
现在位置我们有了3个文件了 commom.php config.php global.php
有了3个文件 程序总体完成了.接下来如何去偷呢?
心急的人可以先试试
建立一个index.php文件 就是首页
你先做好模板 的样子
html先做好.
然后在
<html>
........
........
</html>
的上方插入php代码
如下:
<?php
require './commom.php';
update("index.htm");
$file=readfromfile("cache/index.htm");
$gwrj = cut($file,"<td width=\"307\" height=\"118\">","</td>");
?>
<html>
.......
......
.......
</html>
在你想要插入的地方插入<?php echo $gwrj; ?>
就是从首页中切割出来的国外软件
自己试试
今天就到这里!
下一个接教如何读取分类页面.和简单介绍php模板技术的原理.再下节讲模板,不需要html中出现php代码了.分离开来
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器