您的位置:首页网页设计PHP实例 → 用Php实现链结人气统计

用Php实现链结人气统计

时间:2004/11/7 3:28:00来源:本站整理作者:蓝点我要评论(0)

首先要说明:这个不是主页计数器,虽然原理和它相同。                               

一:准备一个计数文件,存放链结的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" . "\n";//重新生成计数字符串        

break;                                                                           

                                                                                 

}                                                                                

}                                                                                

//写入计数信息                                                                   

$fp=fopen($countfile, "w");                                                      

for($i=0;$i<count($lines);$i++)                                                  

fputs($fp, $lines[$i]);                                                          

fclose($fp);                                                                     

Header("Location: $url");                                                        

?>                                                                               

注:这个是phpuser.com上的不完全版本,我加了一些改动,现在应该是能用的。          

                                                                                 

三:主页中超链结的调用方式应该改为:                                             

doc01                                           

程序功能是:                                                                     

首先将计数文件内容读到数组中                                                     

再从数组中查找指定id号,如找到则$url为相应的文件的真正链接,再将计数加1,        

重新生成计数信息                                                                 

将计数信息写入文件中                                                             

返回链接                                                                         

                                                                                 

四:访问人数引用就是下面这几句,写个function也可以,我偷了把懒,                 

                      谁写好了给我一个  :)                                       

<?php                                                                            

$countfile="count.txt";                                                          

$lines=file($countfile);                                                         

list($sid,$url,$count) = explode("|",$lines[0]);//$lines[0]对应count.txt中       

                                                //第一条记录                     

echo $count;                                                                     

?>                                                                              

 



相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 我的php文件怎么打开_php运算符怎么写 php 如何生成静态页面的函数PHP生成图片缩略图PHP session常见问题集锦及解决办法PHP实现同步远程Mysql

人气排行 DEDE在文章列表文章没有缩略图的不显示图片php+mysq修改用户密码我的php文件怎么打开_如何打开php文件的办法FCKeditor的配置和使用方法使用dedecms建站教程PHP+Ajax实现分页技术图片存储与浏览一例Linux+Apache+PHP+MySQLPHP生成图片缩略图