|
|
此贴首发 destoon二次开发之家 www.zzgeizi.com
转发请转帖路径:http://www.zzgeizi.com/index.php ... p;catid=7&id=75
有些客户要求 在网站底部显示

QQ截图20120714115835.gif (1.42 KB, 下载次数: 0)
下载附件
访问量
2012-7-14 12:01 上传
之类的信息,但是dt现在是没有此功能的
楼主在不改动数据库的情况下,简单的写了个简单的代码统计功能。
在 include/global.func.php 中加入以下代码
其中的 tongji.txt最好在网站根目录建立此文件,注意里面数据格式: 1000|2012-7-14:12 前面1000是总访问量 后面是当天的日期,最后一个是当天访问量。 可以自行修改 此文件
/* 自定义的函数 */
//访问统计
function tongji(){
$t = file_get_contents('tongji.txt');
if($t == ''){
file_put_contents('tongji.txt','1|2012-7-14:1');
$t = '1|'.date('Y-m-d').':1';
}
$arr = explode('|',$t);
$zong = $arr[0] + 1;
$arr_ri = explode(':',$arr[1]);
$date = $arr_ri[0];
$ri = $arr_ri[1];
if($date == date('Y-m-d')){
$ri = $ri+1;
}else{
$ri = 1;
}
file_put_contents('tongji.txt',"$zong|".date('Y-m-d')."

ri");
}
function get_tongji(){
$t = file_get_contents('tongji.txt');
if($t == ''){
return array(1,1);
}else{
$arr = explode('|',$t);
$zong = $arr[0] + 1;
$arr_ri = explode(':',$arr[1]);
return array($zong,$arr_ri[1]);
}
}
function get_online(){
global $db;
$r = $db->get_one("SELECT COUNT(*) AS num FROM {$db->pre}online");
return $r['num']?$r['num']:1;
}
tongji();
/* 自定义的函数 */
foot.htm 中代码
总访问量:{$tongji[0]} 今日访问:{$tongji[1]} 在线用户:{$online} |
|