您的当前位置:首页>全部文章>文章详情

PHP判断网站的访问来源是否是蜘蛛

发表于:2021-07-09 09:18:50浏览:864次TAG: #PHP #蜘蛛 #统计

每天看博客的访问统计,发现新博客半夜或凌晨都有访客的?猜测应该是搜索引擎的蜘蛛爬网站的访问的数据,所以给博客添加一段蜘蛛访问的识别统计。

21.png

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