欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHP网站统计简易版本,文本数据库

程序员文章站 2022-05-20 22:37:04
...
实现 总访问 , 本月访问, 昨日访问, 今日访问统计,使用文本存储,简单好用
自动创建文本数据库,保存本php同目录。显示效果如图:
PHP网站统计简易版本,文本数据库
调用方法:
error_reporting(0);
header ( "Content-type: text/html; charset=utf-8" );
//设置数据文件路径
$file = dirname(__FILE__).'/tongji.db';
$data = unserialize(file_get_contents($file));
//设置记录键值
$total = 'total';
$month = date('Ym');
$today = date('Ymd');
$yesterday = date('Ymd',strtotime("-1 day"));
$tongji = array();
// 总访问增加
$tongji[$total] = $data[$total] + 1;
// 本月访问量增加
$tongji[$month] = $data[$month] + 1;
// 今日访问增加
$tongji[$today] = $data[$today] + 1;
//保持昨天访问
$tongji[$yesterday] = $data[$yesterday];
//保存统计数据
file_put_contents($file, serialize($tongji));
//输出数据
$total = $tongji[$total];
$month = $tongji[$month];
$today = $tongji[$today];
$yesterday = $tongji[$yesterday]?$tongji[$yesterday]:0;
echo "document.write('总访问 {$total}, 本月 {$month}, 昨日 {$yesterday}, 今日 {$today}');";

云栖大会北京站:阿里技术专家难得出镜,这次一下来了100多位?!