这里返回 1 ,0 是因为要在tp3的模板里去做显示判断的。单纯php里用,直接true,false得了!
function is_bot(){
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$botchar = "/(baidu|google|spider|soso|yahoo|sohu-search|yodao|robozilla|bing|sogou)/i";
if(preg_match($botchar, $ua)) {
return "1";
}else{
return "0";
}
}
深入一下,
//备案 不是蜘蛛跳转 显示备案中
u
a
=
s
t
r
t
o
l
o
w
e
r
(
ua = strtolower(
ua=strtolower(_SERVER[‘HTTP_USER_AGENT’]);
b
o
t
c
h
a
r
=
"
/
(
b
a
i
d
u
∣
g
o
o
g
l
e
∣
s
p
i
d
e
r
∣
s
o
s
o
∣
y
a
h
o
o
∣
s
o
h
u
−
s
e
a
r
c
h
∣
y
o
d
a
o
∣
r
o
b
o
z
i
l
l
a
∣
b
i
n
g
∣
s
o
g
o
u
)
/
i
"
;
i
f
(
!
p
r
e
g
m
a
t
c
h
(
botchar = "/(baidu|google|spider|soso|yahoo|sohu-search|yodao|robozilla|bing|sogou)/i"; if(!preg_match(
botchar="/(baidu∣google∣spider∣soso∣yahoo∣sohu−search∣yodao∣robozilla∣bing∣sogou)/i";if(!pregmatch(botchar, $ua)) {
header(‘Content-Type: text/html; charset=utf-8’); //编码格式
echo “
exit;
}