1.在站点中新建一个空白的php文档,命名为:count.php
将下列计数器代码都写在count.php文件里:
<?php
$countfile = "counter.dat";
if (($fp = fopen($countfile,"r+"))== false){
printf("Open file %s failed!",$countfile);
exit;
}
else
{
$count=fread ($fp,filesize($countfile));
$count = $count + 1;
fclose ($fp);
$fp= fopen($countfile,"w+");
fwrite ($fp,$count);
fclose ($fp);
}
?>
保存
2.在站点中再新建一个文档,命名为:counter.dat
用于存储count.php页面计算得到的访问量值。
3.点击要放入计数器的网页位置,打开代码页,输入如下php代码:
<?php
include("count.php");
echo $count;
echo $count;
?>
保存,测试。