您的位置:首页 > 数据库

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

2008-12-07 02:18 162 查看
<script type="text/javascript"><!--
google_ad_client = "pub-4490194096475053";
/* 内容页,300x250,第一屏 */
google_ad_slot = "3685991503";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>//自己做一个网站是用到的,在每个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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息