相思资源网 Design By www.200059.com
首先要说明:这个不是主页计数器,虽然原理和它相同。                               
一:准备一个计数文件,存放链结的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实|实现|现链|链结|结人|人气|气统|统计|计|

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

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

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

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。