凌的博客

您现在的位置是: 首页 > 学无止境 > PHP > 

PHP

php获取访问的蜘蛛名字

2022-03-24 PHP 1122
/**
 * 蜘蛛访问记录
 * @return str
 */
function get_spider()
{
    $user_agent = addslashes(strtolower($_SERVER['HTTP_USER_AGENT']));
    $bot_types = [
        'googlebot' => 'Google',
        'mediapartners-google' => 'Google Adsense',
        'baiduspider' => 'Baidu',
        'sogou spider' => 'Sogou',
        'sogou web' => 'Sogou web',
        'sosospider' => 'SOSO',
        'yahoo' => 'Yahoo',
        'msn' => 'MSN',
        'msnbot' => 'msnbot',
        'sohu' => 'Sohu',
        'yodaoBot' => 'Yodao',
        'twiceler' => 'Twiceler',
        'ia_archiver' => 'Alexa_',
        'iaarchiver' => 'Alexa',
        'slurp' => '雅虎',
        'bot' => '其它蜘蛛',
    ];
    $bot = '';
    foreach ($bot_types as $key => $value) {
        if (strpos($user_agent, $key) !== false) {
            $bot = $value;
            break;
        }
    }
    return $bot;
}


文章评论

0条评论