很多网站采用了
AJAX构造,这样对搜索引擎不是很友好,这里就提供一个识别各个搜索引擎的函数,在判断是搜索引擎后转入专门为搜索引擎提供的页面,方便搜索引擎收录。(当然,你也可以用来强奸搜索引擎 )
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使用。可以达到过滤指定访问者的目标
?>
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使用。可以达到过滤指定访问者的目标
?>