您现在的位置: 军旅同心 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 文章正文
用Php实现链结人气统计
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 14:36:25
首先要说明:这个不是主页计数器,虽然原理和它相同。                               
一:准备一个计数文件,存放链结的url和访问次数,格式如下                          
id|url|count                                                                     
id是用来查找的索引号,url为实际文件的地址,count为次数                           
实例数据:                                                                       
doc01|docs/doc01.html|10                                                         
doc02|docs/doc02.html|10                                                         
二:准备count.php文件,代码如下:                                                
<?php                                                                            
//功能:传入参数id,在计数文件查找相应的url,增加计数,并返回实际的链接           
$countfile="count.txt";                                                          
$lines=file($countfile);//将计数文件内容读到数组$lines中                         
for($i=0;$i<count($lines);$i++)                                                  
{                                                                                
list($sid, $url, $count)=explode("|", $lines[$i]);                               
                                        //分解字符串为$id,$url,$count            
if($sid==$id) //查找指定id                                                       
{                                                                                
$count+=1; //增加计数                                                            
$lines[$i]=$sid . "|" . $url . "|" . "$count" . " ";//重新生成计数字符串        
break;                                                                           
                                                                                 
}                                                                                
}                                                                                
//写入计数信息                                                                   
$fp=fopen($countfile, "w");                                                      
for($i=0;$i<count($lines);$i++)                                                  
fputs($fp, $lines[$i]);                                                          
fclose($fp);                 &

[1] [2] 下一页


 
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告 | 管理登录 |