Products
GG网络技术分享 2025-03-18 16:08 0
做seo的时候遇到一个需求:客户要求收录的内容和展示的内容不一样。
就需要判断用户和蜘蛛来展示不同的页面,来缓冲对seo的影响。
具体应用场景:广告加载、特殊展示处理、紧急关站整改等
不多说直接上【php判断蜘蛛或用户来路展示不同页面】代码:
<?php以上代码可以自定义浏览器以及user-agent.function checkrobot($useragent=''){
static $kw_spiders = array('bot', 'crawl', 'spider' ,'slurp', 'sohu-search', 'lycos', 'robozilla');
static $kw_browsers = array('msie', 'netscape', 'opera', 'konqueror', 'mozilla');
$useragent = strtolower(empty($useragent) ? $_SERVER['HTTP_USER_AGENT'] : $useragent);
if(strpos($useragent, 'http://') === false && dstrpos($useragent, $kw_browsers)) return false;
if(dstrpos($useragent, $kw_spiders)) return true;
return false;
}
function dstrpos($string, $arr, $returnvalue = false) {
if(empty($string)) return false;
foreach((array)$arr as $v) {
if(strpos($string, $v) !== false) {
$return = $returnvalue ? $v : true;
return $return;
}
}
return false;
}
if(checkrobot()){
// 蜘蛛展现页面、代码
header("location:https://www.e6zz.com/index.html")
}else{
// 用户展现页面、代码
header("location:https://www.e6zz.com/user.html");
}
Demand feedback