-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
138 lines (108 loc) · 3.77 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <[email protected]>
// +----------------------------------------------------------------------
// 应用入口文件
date_default_timezone_set('PRC');
function getIP() {
if (getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
}
elseif (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
}
elseif (getenv('HTTP_X_FORWARDED')) {
$ip = getenv('HTTP_X_FORWARDED');
}
elseif (getenv('HTTP_FORWARDED_FOR')) {
$ip = getenv('HTTP_FORWARDED_FOR');
}
elseif (getenv('HTTP_FORWARDED')) {
$ip = getenv('HTTP_FORWARDED');
}
else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
function getApplication()
{
$uri = $_SERVER['REQUEST_URI'];
$uriArr = explode("/",$uri);
if(in_array('Service',$uriArr)){
define('CURRENTAPP','Service');
define('VisitorModuleKey','visitor:service:traffic');
define('VisitorModuleSet','visitor:service:set');
}elseif(in_array('Log',$uriArr)){
define('CURRENTAPP','Log');
define('VisitorModuleKey','visitor:log:traffic');
define('VisitorModuleSet','visitor:log:set');
}else{
define('CURRENTAPP','Admin');
define('VisitorModuleKey','visitor:admin:traffic');
define('VisitorModuleSet','visitor:admin:set');
}
if(in_array('login',$uriArr) || in_array("login.html",$uriArr)){
if(CURRENTAPP == 'Service'){
define('VisitorLoginHash','visitor:service:login:hash');
}elseif(CURRENTAPP == 'Log'){
define('VisitorLoginHash','visitor:log:login:hash');
}else{
define('VisitorLoginHash','visitor:admin:login:hash');
}
}
}
getApplication();
define('RedisHost','172.30.2.153');
define('RedisPort','6379');
define('VisitorHash','visitor:ip:hash');
define('VisitorSet','visitor:ip:set');
//每个模块都记录浏览量:
$redis = new Redis();
if($conn = $redis->connect(RedisHost,RedisPort)){
$ip = getIP();
$redis->incr(VisitorModuleKey,1); //对应模块访问量加1;
$redis->sadd(VisitorModuleSet,$ip);//把ip记录对应的访问模块;
if(defined('VisitorLoginHash')){
$redis->hincrby(VisitorLoginHash,$ip,1); //记录IP登录次数;
//$redis->hset(VisitorLoginHash,$ip,strval(date('Y-m-d H:i:s')));
}
//单独记录IP地址访问次数;
$redis->hincrby(VisitorHash,$ip,1);
//记录系统独立访客;
$redis->sadd(VisitorSet,$ip);
//记录当天访客;
$date =date('Y-m-d');
$hashDate = $date.":"."ip:hash";
$redis->hincrby($hashDate,$ip,1);
$redis->close();
}
// 检测PHP环境
if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !');
// 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false
define('APP_DEBUG',true);//
/**
* 缓存目录设置
* 此目录必须可写,建议移动到非WEB目录
*/
define ( 'RUNTIME_PATH', './Runtime/' );
//定义公共模块的目录,放到应用目录外
define('COMMON_PATH','./Common/');
//关闭目录安全文件的生成
define('BUILD_DIR_SECURE', false);
// 定义应用目录
define('APP_PATH','./Application/');
define('BASE_DIR', dirname(__FILE__));
// 定义BASE_DIR(即index.php)相对于DOCMENT ROOT的相对路径前缀
$prefix = str_replace($_SERVER["DOCUMENT_ROOT"],'',str_replace('\\','/',BASE_DIR));
define('PREFIX_DIR',$prefix);
//echo PREFIX_DIR;
// 引入ThinkPHP入口文件
require './ThinkPHP/ThinkPHP.php';
// 亲^_^ 后面不需要任何代码了 就是如此简单