Home > php教程 > php手册 > body text

PHP website statistics simple version, text database

WBOY
Release: 2016-07-06 13:29:19
Original
995 people have browsed it

Realize total visits, visits this month, yesterday's visits, today's visits statistics, use text storage, simple and easy to use
Automatically create a text database and save this php in the same directory. The display effect is as shown below:
PHP website statistics simple version, text database
Calling method:
<?php<code class="prettyprint linenums lang-php"><?php<br> error_reporting(0);<br> header ( "Content-type: text/html; charset=utf-8" );<br> //设置数据文件路径<br> $file = dirname(__FILE__).'/tongji.db';<br> $data = unserialize(file_get_contents($file));<br> //设置记录键值<br> $total = 'total';<br> $month = date('Ym');<br> $today = date('Ymd');<br> $yesterday = date('Ymd',strtotime("-1 day"));<br> $tongji = array();<br> // 总访问增加<br> $tongji[$total] = $data[$total]   1;<br> // 本月访问量增加<br> $tongji[$month] = $data[$month]   1;<br> // 今日访问增加<br> $tongji[$today] = $data[$today]    1;<br> //保持昨天访问<br> $tongji[$yesterday] = $data[$yesterday];<br> //保存统计数据<br> file_put_contents($file, serialize($tongji));<br> //输出数据<br> $total = $tongji[$total];<br> $month = $tongji[$month];<br> $today = $tongji[$today];<br> $yesterday = $tongji[$yesterday]?$tongji[$yesterday]:0;<br> echo  "document.write('总访问 {$total}, 本月 {$month}, 昨日 {$yesterday}, 今日 {$today}');"; error_reporting(0);

header ( "Content-type: text/html; charset=utf-8" );

//Set data file path

$file = dirname(__FILE__).'/tongji.db'; $data = unserialize(file_get_contents($file)); //Set record key value $total = 'total'; $month = date('Ym'); $today = date('Ymd'); $yesterday = date('Ymd',strtotime("-1 day")); $tongji = array(); // Total visits increased $tongji[$total] = $data[$total] 1; // Increased visits this month $tongji[$month] = $data[$month] 1; // Increased visits today $tongji[$today] = $data[$today] 1; //Keep yesterday’s visit $tongji[$yesterday] = $data[$yesterday]; //Save statistics file_put_contents($file, serialize($tongji)); //Output data $total = $tongji[$total]; $month = $tongji[$month]; $today = $tongji[$today]; $yesterday = $tongji[$yesterday]?$tongji[$yesterday]:0; echo "document.write('Total visits {$total}, this month {$month}, yesterday {$yesterday}, today {$today}');"; Yunqi Conference Beijing Station: It’s rare for Alibaba’s technical experts to appear on camera. More than 100 of them came this time? !
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!