计数器
说明:
实现原理是:利用PHP的功能函数去读取文本文件的数据,从而实现数据的统计。
1. 新建一个文件取名为:counter.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];
?>
2. 把下面的代码代码放到你想显示点击次数的地方,达到文件显示目的。
include ("counter.php");
?>
3. 最后新建一个文件counter.txt.修改其权限为 777。
简单的计数器就实现了。
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn