本文教你小偷程序之幾個基本函數(第二天)
發表時間:2024-05-14 來源:明輝站整理相關軟件相關文章人氣:
[摘要]第一天的教程連接地址http://www.vipcn.com/infoview/Article_3751.html今天教第二天.有個朋友說的好,其實教功夫也是變相的教你怎么殺人,可是不說出來.所以這個教程從下一篇開始就改個名字叫<遠程操作對方數據程序>有點土比小偷好聽第二天.教幾個函數...
第一天的教程連接地址
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代碼了.分離開來