首先要说明:这个不是主页计数器,虽然原理和它相同。                               
一:准备一个计数文件,存放链结的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上的不完全版本,我加了一些改动,现在应该是能用的。          

三:主页中超链结的调用方式应该改为:                                             
<a href="count.php?id=doc01">doc01</a>                                           
程序功能是:                                                                     
首先将计数文件内容读到数组中                                                     
再从数组中查找指定id号,如找到则$url为相应的文件的真正链接,再将计数加1,        
重新生成计数信息                                                                 
将计数信息写入文件中                                                             
返回链接                                                                         

四:访问人数引用就是下面这几句,写个function也可以,我偷了把懒,                 
                      谁写好了给我一个  :)                                       
<?php                                                                            
$countfile="count.txt";                                                          
$lines=file($countfile);                                                         
list($sid,$url,$count) = explode("|",$lines[0]);//$lines[0]对应count.txt中       
                                                //第一条记录                     
echo $count;                                                                     
?>                                                                              


标签:
|用P|Ph|hp|p实|实现|现链|链结|结人|人气|气统|统计|计|

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com

评论“用Php实现链结人气统计”

暂无“用Php实现链结人气统计”评论...

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?