Beispiel #1
0
            }
        }
    }
}
/* ===================================== 配置部分 ========================================== */
$check_time = 300;
//10分钟检查一次
$online_time = 1800;
//统计30分钟的在线用户
$app = t($_GET['app']) ? t($_GET['app']) : 'square';
$mod = t($_GET['mod']) ? t($_GET['mod']) : 'Index';
$act = t($_GET['act']) ? t($_GET['act']) : 'index';
$action = $app . '/' . $mod . '/' . $act;
$uid = isset($_GET['uid']) ? intval($_GET['uid']) : 0;
$uname = t($_GET['uname']) ? t($_GET['uname']) : 'guest';
$agent = getBrower();
$ip = getClientIp();
$refer = '站内';
isset($_SERVER['HTTP_REFERER']) && ($refer = addslashes($_SERVER['HTTP_REFERER']));
$isGuest = $uid == -1 || $uid == 0 ? 1 : 0;
$isIntranet = substr($ip, 0, 2) == '10.' ? 1 : 0;
$cTime = time();
$ext = '';
//记录在线统计.
if ($_GET['action'] == 'trace') {
    /* ===================================== step 1 record track ========================================== */
    $result = Capsule::table('online_logs')->insert(array('day' => date('Y-m-d'), 'uid' => $uid, 'uname' => $uname, 'action' => $action, 'refer' => $refer, 'isGuest' => $isGuest, 'isIntranet' => $isIntranet, 'ip' => $ip, 'agent' => $agent, 'ext' => $ext));
    /* ===================================== step 2 update hits ========================================== */
    //memcached更新.写入全局点击量.每个应用的点击量.每个版块的点击量.
    /* ===================================== step 3 update heartbeat ========================================== */
    if (cookie('online_update') + $check_time < $cTime) {
Beispiel #2
0
    public function getLastSql()
    {
        return $this->queryStr;
    }
}
// 类定义结束
$db = new SimpleDB($config);
$data['publicid'] = safe($_GET['publicid']);
$data['uid'] = safe($_GET['uid']);
$data['module_name'] = isset($_GET['_addons']) ? safe($_GET['_addons']) : safe($_GET['m']);
$data['controller_name'] = isset($_GET['_controller']) ? safe($_GET['_controller']) : safe($_GET['c']);
$data['action_name'] = isset($_GET['_action']) ? safe($_GET['_action']) : safe($_GET['a']);
unset($_GET['publicid'], $_GET['uid'], $_GET['_addons'], $_GET['_controller'], $_GET['_action'], $_GET['m'], $_GET['c'], $_GET['a'], $_GET['mdm']);
$data['param'] = json_encode($_GET);
$data['ip'] = getClientIp();
$data['brower'] = getBrower();
$data['referer'] = $_SERVER['HTTP_REFERER'];
$data['cTime'] = time();
$sql = "INSERT INTO " . $config['DB_PREFIX'] . "visit_log (publicid,uid,module_name,controller_name,action_name,param,ip,brower,referer,cTime) VALUES ( '{$data[publicid]}','{$data[uid]}','{$data[module_name]}','{$data[controller_name]}','{$data[action_name]}','{$data[param]}','{$data[ip]}','{$data[brower]}','{$data[referer]}','{$data[cTime]}');";
// dump ( $sql );
echo $db->execute("{$sql}");
// dump ( $result );
// 自动删除7天前的数据
$file = 'delete_visit_log.lock';
$time = filemtime(RUNTIME_PATH . $file);
$over_time = $data['cTime'] - 7 * 24 * 3600;
if ($time === false || $time < $over_time) {
    $fo = fopen(RUNTIME_PATH . $file, "w");
    $sql = "DELETE FROM " . $config['DB_PREFIX'] . "visit_log where cTime<" . $over_time;
    //dump ( $sql );
    $db->execute("{$sql}");