原文地址:PHP判断来访是蜘蛛还是普通用户作者:mylimh
PHP判断来访是蜘蛛还是普通用户--------------收藏(红黑联盟)
<?php
$flag = false;
$tmp = $_SERVER['HTTP_USER_AGENT'];
if(strpos($tmp, 'Googlebot') !== false){
$flag =
true;
} else if(strpos($tmp, 'Baiduspider') >0){
$flag =
true;
} else if(strpos($tmp, 'Yahoo! Slurp') !== false){
$flag =
true;
} else if(strpos($tmp, 'msnbot') !== false){
$flag =
true;
} else if(strpos($tmp, 'Sosospider') !== false){
$flag =
true;
} else if(strpos($tmp, 'YodaoBot') !== false || strpos($tmp, 'OutfoxBot') !== false){
$flag =
true;
} else if(strpos($tmp, 'Sogou web spider') !== false || strpos($tmp, 'Sogou Orion spider') !== false){
$flag =
true;
} else if(strpos($tmp, 'fast-webcrawler') !== false){
$flag =
true;
} else if(strpos($tmp, 'Gaisbot') !== false){
$flag =
true;
} else if(strpos($tmp, 'ia_archiver') !== false){
$flag =
true;
} else if(strpos($tmp, 'altavista') !== false){
$flag =
true;
} else if(strpos($tmp, 'lycos_spider') !== false){
$flag =
true;
} else if(strpos($tmp, 'Inktomi slurp') !== false){
$flag =
true;
}
if($flag == false){
header("Location:
http://www.hao123.com" . $_SERVER['REQUEST_URI']);
//
自动转到http://www.hao123.com 对应的网页
//
$_SERVER['REQUEST_URI'] 为域名后面的路径
// 或
换成header("Location: http://www.hao123.com/abc/d.php");
exit();
}
?>
<?php
$flag = false;
$tmp = $_SERVER['HTTP_USER_AGENT'];
if(strpos($tmp, 'Googlebot') !== false){
} else if(strpos($tmp, 'Baiduspider') >0){
} else if(strpos($tmp, 'Yahoo! Slurp') !== false){
} else if(strpos($tmp, 'msnbot') !== false){
} else if(strpos($tmp, 'Sosospider') !== false){
} else if(strpos($tmp, 'YodaoBot') !== false || strpos($tmp, 'OutfoxBot') !== false){
} else if(strpos($tmp, 'Sogou web spider') !== false || strpos($tmp, 'Sogou Orion spider') !== false){
} else if(strpos($tmp, 'fast-webcrawler') !== false){
} else if(strpos($tmp, 'Gaisbot') !== false){
} else if(strpos($tmp, 'ia_archiver') !== false){
} else if(strpos($tmp, 'altavista') !== false){
} else if(strpos($tmp, 'lycos_spider') !== false){
} else if(strpos($tmp, 'Inktomi slurp') !== false){
}
if($flag == false){
}
?>