|
|
|
|
<?php
|
|
|
|
|
$file = SYSTEM_ROOT."/log.txt";
|
|
|
|
|
if(!file_exists($file)){
|
|
|
|
|
touch($file);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
$fp=fopen($file,'r+');
|
|
|
|
|
$content='';
|
|
|
|
|
if (flock($fp,LOCK_EX)){
|
|
|
|
|
while (($buffer=fgets($fp,1024))!=false){
|
|
|
|
|
$content=$content.$buffer;
|
|
|
|
|
}
|
|
|
|
|
$tjdate=unserialize($content);
|
|
|
|
|
//设置记录键值
|
|
|
|
|
$tjtotal = 'total';
|
|
|
|
|
$tjmonth = date('Ym');
|
|
|
|
|
$tjtoday = date('Ymd');
|
|
|
|
|
$tjyesterday = date('Ymd',strtotime("-1 day"));
|
|
|
|
|
$tongji = array();
|
|
|
|
|
if(strpos($_SERVER['REQUEST_URI'],'admin')==false){
|
|
|
|
|
|
|
|
|
|
$tongji[$tjtotal] = $tjdate[$tjtotal] + 1;
|
|
|
|
|
// 本月访问量增加
|
|
|
|
|
$tongji[$tjmonth] = $tjdate[$tjmonth] + 1;
|
|
|
|
|
// 今日访问增加
|
|
|
|
|
$tongji[$tjtoday] = $tjdate[$tjtoday] + 1;
|
|
|
|
|
//保持昨天访问
|
|
|
|
|
$tongji[$tjyesterday] = $tjdate[$tjyesterday];
|
|
|
|
|
ftruncate($fp,0); // 将文件截断到给定的长度
|
|
|
|
|
rewind($fp); // 倒回文件指针的位置
|
|
|
|
|
fwrite($fp, serialize($tongji));
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
$tongji[$tjtotal] = $tjdate[$tjtotal] ;
|
|
|
|
|
// 本月访问量增加
|
|
|
|
|
$tongji[$tjmonth] = $tjdate[$tjmonth];
|
|
|
|
|
// 今日访问增加
|
|
|
|
|
$tongji[$tjtoday] = $tjdate[$tjtoday];
|
|
|
|
|
//保持昨天访问
|
|
|
|
|
$tongji[$tjyesterday] = $tjdate[$tjyesterday];
|
|
|
|
|
}
|
|
|
|
|
flock($fp,LOCK_UN);
|
|
|
|
|
fclose($fp);
|
|
|
|
|
//输出数据
|
|
|
|
|
$tjtotal = $tongji[$tjtotal];
|
|
|
|
|
$tjmonth = $tongji[$tjmonth];
|
|
|
|
|
$tjtoday = $tongji[$tjtoday];
|
|
|
|
|
$tjyesterday = $tongji[$tjyesterday]?$tongji[$tjyesterday]:0;
|
|
|
|
|
//访总问 {$tjtotal} 本月 {$tjmonth} 昨日 {$tjyesterday} 今日 {$tjtoday}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//记录访问IP
|
|
|
|
|
$time = date("Y-m-d H:i:s");//$time把访问时间记录下来 如果向把具体年份写出来请把y更改为Y
|
|
|
|
|
$date = date("Y-m-d");
|
|
|
|
|
//注意Y要是英文半角哦
|
|
|
|
|
$ip = $_SERVER["REMOTE_ADDR"];//$ip记录访问者IP
|
|
|
|
|
$save = "<li> IP:".$ip." "." time:".$time."</li> \n";//把上面两个结合并添加空格
|
|
|
|
|
//不想要空格可以删除$save中的." "
|
|
|
|
|
//echo $save;//echo 保存
|
|
|
|
|
file_put_contents("include/IP/"."IP_".$date.".txt",$save,FILE_APPEND);//通过$save保存至txt文档
|
|
|
|
|
//header('Location: http://xxx.xxx/index.html');
|
|
|
|
|
//跳转到主页,不要照搬,把xxx.xxx换成你的域名(如果主页不是index.html的话要更换/index.html)
|
|
|
|
|
//如果你的网站就是php的话请把旧主页更换为其他名字,例如:a.php /index.html也要换成/a.php
|
|
|
|
|
?>
|