1.首先在php根目录下面建三个文件,count.php,count.txt,index.php
2.将count.php里面添加如下代码:
<?php
//选择 counter.txt文本文件
$counter_file = ("counter.txt");
//打开文本文件
$visits = file($counter_file);
//自动加1
$visits[ 0]++;
//这个点击自动记录
$fp = fopen($counter_file, "w");
//写入counter.txt文件中,从而记录了
fputs($fp, "$visits[0]");
//关闭文件
fclose($fp);
//显示次数
echo $visits[0];
?>
3.把count.txt改成可写权限777
4.在index.php中加入如下代码
<?php
include ("count.php");
?>
原文地址:http://shmilyfl.blog.51cto.com/8897986/1700309