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

//自己做一个网站是用到的,在每个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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值