php判断搜索引擎蜘蛛过来的就打开A页面,直接输入打开就访问B页面?

新手上路,请多包涵

如题尝试过用下面的代码有些页面 好像不太行!

<?php
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()){
    include_once('index.php');
    
}else{
    include_once('502.html');
}
?>

有没有更新好,更简单的方法?

阅读 2.3k
2 个回答

应该不是检查user-agent,而是检查referer。
referer可以判断是从什么网站跳转过来的。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题