function is_bot(){
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$botchar = "/(baidu|google|spider|soso|yahoo|sohu-search|yodao|robozilla)/i";
if(preg_match($botchar, $ua)) {
return true;
}else{
return false;
}
}
自用HTTP HEAD里的USER_AGENT进行判断,像Google的UA为GoogleBot,百度的为Baiduspider,基本上所有的搜索引擎都会增加这些字符以表明Robot的身份。
使用方法:(直接复制一段程序过来,自己根据需要修改)
<?php
if(is_bot()){
header('Location: http://www.phpchinaz.cn/);
}else{
header('Location:./human. html');
}
//配合HTACCESS使用。可以达到过滤指定访问者的目标
?>
7103



被折叠的 条评论
为什么被折叠?



