TAY
笔记 · · 阅读 156

php 判断访客是否为搜索引擎蜘蛛

function fromRobot($except = '') {
   $ua = strtolower ( $_SERVER ['HTTP_USER_AGENT'] );
   $botchar = "/(baidu|google|spider|soso|yahoo|sohu-search|yodao|robozilla|AhrefsBot|Bing)/i";
   $except ? $botchar = str_replace ( $except . '|', '', $botchar ) : '';
   if (preg_match ( $botchar, $ua )) {
      return true;
   }
   return false;
}

if(fromRobot()){
    // 执行
}
目录