艺术迷网
艺术迷 >> 网页设计 >> PHP学习 >> 跟我学小偷程序之几个基本函数(第二天)
2006-10-16   作者:佚名   来源:清风网络学院   点击:1444
页面功能: 【评论】有错就点】 【字体: 】 【打印】 【关闭【收藏本页】收藏到365Key
 
今天教第二天.
有个朋友说的好‚其实教功夫也是变相的教你怎么杀人‚可是不说出来.
所以这个教程从下一篇开始就改个名字
叫<远程操作对方数据程序>有点土比小偷好听
第二天.
教几个函数给大家.
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代码了.分离开来


声明:本站刊载此文不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。如有疑问请与站长联系。
网友评论

RE:跟我学小偷程序之几个基本函数(第二天)

 回复者:匿名 时间:2007-12-6
xvcbxcv

RE:跟我学小偷程序之几个基本函数(第二天)

 回复者:匿名 时间:2007-12-6
asdfgasdgasfg
发表评论
您的姓名: 匿名发送
电子邮件:
评论内容:
不能超过100个字符



所有留言只代表网友个人观点,不代表本站观点。
请各位遵纪守法并注意语言文明。
新闻搜索
关 键 词:
搜索范围:
全站精华
图文精彩
平面设计QQ群:42326012;技术群:38389792;
本站部分图文内容取自互联网。您若发现有侵犯您著作权行为,请及时告知,我们将在第一时间删除侵权作品、停止继续传播。
Copyright 2006-2007,版权所有 www.fansart.com tc_show@126.com QQ:44550498