访问统计(排除爬虫)
用到的组件是 jenssegers/agent
$agent = new Agent();
$useragant = $agent->getUserAgent();
switch (true) {
case $agent->isMobile():
$device_type = 'Mobile';
break;
case $agent->isTablet():
$device_type = 'Tablet';
break;
case $agent->isDesktop():
$device_type = 'Desktop';
break;
case $agent->isRobot():
$device_type = 'Robot';
break;
default:
$device_type = 'Unknow';
break;
}
// $agent->isRobot()能区分部分爬虫但不全面
// 包含spider|Spider的也认为是爬虫
$isnot_robot = $device != 'Robot' && !$agent->match('spider');
$device_type;// Mobile|Tablet|Desktop|Robot
$device = $agent->device();// iphone|nexus|WebKit|Samsung..(或false)
本作品采用《CC 协议》,转载必须注明作者和本文链接