`
txf2004
  • 浏览: 7065250 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

今,昨,周,月 页面访问统计

阅读更多

//自己做一个网站是用到的,在每个php文件中调用page_count()这个函数即可!

放在数据库配置文件中是个好注意!

// 页面访问统计表
CREATE TABLE statistics
(
today int not null,
yesterday int not null,
this_week int not null,
this_month int not null,
overall int not null,
date int not null
)ENGINE=MyISAM DEFAULT CHARSET=utf8;

// 页面访问统计
function page_count() {
global $mysql;
if (isset($_SESSION['js']))
return false;
$sql = "SELECT * FROM statistics";
$mysql->MysqlQuery($sql);
$re_arr = $mysql->MysqlResultArray();

$today = $re_arr[0]['today']; // 今天
$yesterday = $re_arr[0]['yesterday']; // 昨天
$this_week = $re_arr[0]['this_week']; // 本周
$this_month = $re_arr[0]['this_month']; //本月
$overall = $re_arr[0]['overall']; // 所有
$date = $re_arr[0]['date'];

if (date('d') == date('d', $date)) { // 现在时间的天数与上次访问时候天数
$today += 1;
}else {
$yesterday = $today;
$today = 1;
}

if (date('W') == date('W', $date)) {
$this_week += 1;
}else {
$this_week = 1;
}

if (date('m') == date('m', $date)) {
$this_month += 1;
}else {
$this_month = 1;
}

$overall+=1;
$time = time();
$sql = "UPDATE statistics SET today=$today, yesterday=$yesterday, this_week=$this_week, this_month=$this_month, overall=$overall, date=$time";
$mysql->MysqlQuery($sql);
$_SESSION['js'] = true;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics