首页 | 站长免费中心 | 新手上路 | 网站运营 | 网页制作 | 图片设计 | 动画设计 | 网页编程 | 网页特效 | 本站专题 | 虚拟主机 | 域名注册 | 网站建设 | 程序下载
       免费空间资源 | 新闻咨询 | 免费域名 | 免费网盘 | 网站推广 | 网站策划 | 建站经验 | 网站优化 | 网页代码 | 源码下载 | 音乐小偷 | 网络赚钱 | 论坛交流
网站建设
网站建设
虚拟主机
虚拟主机
域名注册
域名注册
711网络首页
站长工具
站长工具
网站源码
网站源码
站长论坛
站长论坛

 711网络 网页编程音乐小偷

小偷程序之几个基本函数(第二天)

来源: 互联网    日期:2006-5-10
 
第一天的教程连接地址
http://im286.com/viewthread.php?tid=525607
今天教第二天.
有个朋友说的好,其实教功夫也是变相的教你怎么杀人,可是不说出来.
所以这个教程从下一篇开始就改个名字
叫<远程操作对方数据程序>有点土比小偷好听
第二天.
教几个函数给大家.
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代码了.分离开来


更多的小偷程序之几个基本函数(第二天)请到论坛查看: http://BBS.TC711.COM



【 双击滚屏 】 【 评论 】 【 收藏 】 【 打印 】 【 关闭 】 来源: 互联网    日期:2006-5-10   

发 表 评 论
查看评论

  您的大名:
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
认证编码: 刷新验证码
点评内容: 字数0
  精品推荐  
  本月推荐  
  友情赞助  

关于我们 | 联系我们 | 广告投放 | 留言反馈 | 免费程序 | 虚拟主机 | 网站建设 |  网站推广 |  google_sitemap baidu_sitemap RSS订阅
本站所有资源均来自互联网,如有侵犯您的版权或其他问题,请通知管理员,我们会在最短的时间回复您
Copyright © 2005-2015 Tc711.Com All Rights Reserved 版权所有·711网络   蜀ICP备05021915号
110网监备案 信息产业备案 不良信息举报