/
index.php
executable file
·250 lines (193 loc) · 9.38 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
// 应用入口文件
define("WB_AKEY", '1862350536');
define("WB_SKEY", '4c77f5694e6f3e82278e831390355bb8');
define("WB_CALLBACK_URL", 'http://www.sutuijian.com/index.php/Home/Test/callback');
// 检测PHP环境
if (version_compare(PHP_VERSION, '5.3.0', '<'))
die('require PHP > 5.3.0 !');
// 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false
define('APP_DEBUG', true);
// 定义应用目录
define('APP_PATH', './sutuijian/');
define('__URL__', 'http://123.57.79.2');
define('__SELF__', 'http://123.57.79.2/Public');
/* * ***************************************************以下是对于访问pc或微信页面时,各终端的不同处理***************************************** */
//echo "<pre>";var_dump($_SERVER);echo "</pre>";
//如果是微信,只需要限制访问pc的情况
if (is_weixin()) {
//如果微信访问pc的职位详情页面
if (isset($_GET['s']) && strpos($_GET['s'], "/jobid/") && strpos($_GET['s'], "/comid")) {
$requesString = explode("/jobid/", $_GET['s']);
$requesString = explode("/share", $requesString[1]);
$hJobID = rtrim($requesString[0], ".html");
// header('Location: http://www.renrenlie.com/Home/Webchatnew/job_detail/jobid/' . $hJobID);
// exit();
}
to_weixin();
// header('Location:http://m.renrenlie.com/');
} elseif (is_mobile_request()) {//如果是手机
/* * **********************************************手机访问pc页面begin************************************************ */
//如果手机访问pc的职位详情页面
if (isset($_GET['s']) && strpos($_GET['s'], "/jobid/") && strpos($_GET['s'], "/comid")) {
$requesString = explode("/jobid/", $_GET['s']);
$requesString = explode("/share", $requesString[1]);
$hJobID = rtrim($requesString[0], ".html");
header('Location: http://m.renrenlie.com/index.php?s=/Job/job_detail_new/jobid/' . $hJobID);
exit();
}
//如果手机访问pc的职位详情页面
if (!empty($_GET['jobid']) && !empty($_GET['comid'])) {
header('Location: http://m.renrenlie.com/index.php?s=/Job/job_detail_new/jobid/' . $_GET['jobid']);
die();
}
/* * **********************************************手机访问pc页面end************************************************ */
to_mobile();
/* * **********************************************手机访问weixin页面begin************************************************ */
//手机访问微信的职位详情
if (strpos($_SERVER['REQUEST_URI'], "/Webchatnew/job_detail/jobid/") !== false) {
$requesString = explode("/jobid/", $_SERVER['REQUEST_URI']);
$requesString = explode("&share=", $requesString[1]);
header("Location: http://m.renrenlie.com/index.php?s=/Job/job_detail_new/jobid/" . $requesString[0]);
die;
}
//手机访问weixin红包
if (strpos($_SERVER['QUERY_STRING'], "s=/Home/Webchatactive/wxredpackage") !== false) {
header('Location:http://m.renrenlie.com/index.php?s=/Active/activities4.html');
exit();
}
/* * **********************************************手机访问weixin页面end************************************************ */
header('Location:http://m.renrenlie.com/');
exit();
} else {
//如果是pc,只要限制微信即可
//pc访问微信职位详情页面
if (strpos($_SERVER['REQUEST_URI'], "/Webchatnew/job_detail/jobid/") !== false) {
$requesString = explode("/jobid/", $_SERVER['REQUEST_URI']);
$requesString = explode("&share=", $requesString[1]);
// header("Location: http://www.renrenlie.com/Home/Index/job_detail_redirect/jobid/" . $requesString[0]);
// die;
}
// to_pc();
//pc访问微信红包页面
if (strpos($_SERVER['QUERY_STRING'], "s=/Home/Webchatactive/wxredpackage") !== false) {
header('Location:http://www.renrenlie.com/index.php?s=/Home/Index/activities4.html');
exit();
}
}
//判断是不是手机
function is_mobile_request() {
$_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';
$mobile_browser = '0';
if (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', strtolower($_SERVER['HTTP_USER_AGENT'])))
$mobile_browser++;
if ((isset($_SERVER['HTTP_ACCEPT'])) and ( strpos(strtolower($_SERVER['HTTP_ACCEPT']), 'application/vnd.wap.xhtml+xml') !== false))
$mobile_browser++;
if (isset($_SERVER['HTTP_X_WAP_PROFILE']))
$mobile_browser++;
if (isset($_SERVER['HTTP_PROFILE']))
$mobile_browser++;
$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4));
$mobile_agents = array(
'w3c ', 'acs-', 'alav', 'alca', 'amoi', 'audi', 'avan', 'benq', 'bird', 'blac',
'blaz', 'brew', 'cell', 'cldc', 'cmd-', 'dang', 'doco', 'eric', 'hipt', 'inno',
'ipaq', 'java', 'jigs', 'kddi', 'keji', 'leno', 'lg-c', 'lg-d', 'lg-g', 'lge-',
'maui', 'maxo', 'midp', 'mits', 'mmef', 'mobi', 'mot-', 'moto', 'mwbp', 'nec-',
'newt', 'noki', 'oper', 'palm', 'pana', 'pant', 'phil', 'play', 'port', 'prox',
'qwap', 'sage', 'sams', 'sany', 'sch-', 'sec-', 'send', 'seri', 'sgh-', 'shar',
'sie-', 'siem', 'smal', 'smar', 'sony', 'sph-', 'symb', 't-mo', 'teli', 'tim-',
'tosh', 'tsm-', 'upg1', 'upsi', 'vk-v', 'voda', 'wap-', 'wapa', 'wapi', 'wapp',
'wapr', 'webc', 'winw', 'winw', 'xda', 'xda-'
);
if (in_array($mobile_ua, $mobile_agents))
$mobile_browser++;
if (strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false)
$mobile_browser++;
// Pre-final check to reset everything if the user is on Windows
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows') !== false)
$mobile_browser = 0;
// But WP7 is also Windows, with a slightly different characteristic
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone') !== false)
$mobile_browser++;
if ($mobile_browser > 0)
return true;
else
return false;
}
//判断是是不是微信
function is_weixin() {
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
return true;
}
return false;
}
//判断是pc
function from_to_weixin() {
if (is_weixin() === false) {
if (is_mobile_request() === false) {
// header('Location: http://www.renrenlie.com/');
// die;
}
}
}
function to_weixin() {
$referurl = $_SERVER['QUERY_STRING'];
if (!empty($referurl)) {
$arShare = conn_db();
foreach ($arShare as $v) {
if (strpos("s=" . $v['pcurl'], rtrim($referurl, ".html")) !== false) {
header("location:" . "http://" . $_SERVER['HTTP_HOST'] . $v['wxurl']);
die;
}
}
}
}
function to_mobile() {
$referurl = $_SERVER['QUERY_STRING'];
if (!empty($referurl)) {
$arShare = conn_db();
foreach ($arShare as $v) {
if (strpos("s=" . $v['wxurl'], rtrim($referurl, ".html")) !== false || strpos("s=" . $v['pcurl'], rtrim($referurl, ".html")) !== false) {
header("location:" . "http://m.renrenlie.com" . $v['wapurl']);
die;
}
}
}
}
function to_pc() {
$referurl = $_SERVER['QUERY_STRING'];
if (!empty($referurl)) {
$arShare = conn_db();
foreach ($arShare as $v) {
if (strpos("s=" . $v['wxurl'], rtrim($referurl, ".html")) !== false) {
header("location:" . "http://" . $_SERVER['HTTP_HOST'] . $v['pcurl']);
die;
}
}
}
}
//连接数据库
function conn_db() {
@$conn = mysql_connect("127.0.0.1", "root", ""); //线下
// @$conn = mysql_connect("localhost", "myrenrenlie", "W8ydG7TxHRaYZVcT"); //线上
if (!$conn) {
die(mysql_error());
}
$db_selected = mysql_select_db("renrenlie", $conn);
// $db_selected = mysql_select_db("lierenren", $conn); //线上
if (!$db_selected) {
die(mysql_error());
}
//查找数据
$sql = "select * from stj_share_info";
$re = mysql_query($sql); //返回resource或false
if (!$re) {
die(mysql_error());
}
while ($arr = mysql_fetch_assoc($re)) { //返回的数组包括关联数组
$arShare[] = $arr;
}
return $arShare;
}
// 引入ThinkPHP入口文件
require './ThinkPHP/ThinkPHP.php';