每天看博客的访问统计,发现新博客半夜或凌晨都有访客的?猜测应该是搜索引擎的蜘蛛爬网站的访问的数据,所以给博客添加一段蜘蛛访问的识别统计。
/**
* 判断是否是蜘蛛
*/
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;
}