用户画像统计分析之获取用户浏览器-php实用功能记录(四)

阅读697评论0

大数据,用户画像的其中一个元素,用户所用的浏览器,具体能干嘛,,,大家脑补吧
下面这个方法所包含的浏览器可能不是很全,有遗漏的朋友可以补上去哈

function GetBrowser($agent){
if(preg_match('/MSIE\s([^\s;]+)/i',$agent,$match)){    
$browser = 'IE '.$match[1];//IE
}elseif(preg_match('/FireFox\/([^\s]+)/i',$agent,$match)){
$browser = '火狐 '.$match[1];//火狐
}elseif(preg_match('/Chrome\/([^\s]+)/i',$agent,$match)){
$browser = '谷歌 '.$match[1];//谷歌
}elseif(preg_match('/safari\/([^\s]+)/i',$agent,$match)){
$browser = 'Safari '.$match[1];
}elseif(preg_match('/Opera[\s\/]([^\s]+)/i',$agent,$match)){
$browser = '欧朋 '.$match[1];//欧朋
}elseif(preg_match('/OmniWeb\/(v*)([^\s|;]+)/i',$agent,$match)){
$browser='OmniWeb '.$match[2];
}elseif(preg_match('/Netscape([\d]*)\/([^\s]+)/i',$agent,$match)){
$browser='网景 '.$match[2];
}elseif(preg_match('/Lynx\/([^\s]+)/i',$agent, $match)){
$browser=$match[1];
}elseif(preg_match('/360SE/i',$agent, $match)){
$browser='360浏览器';
}elseif(preg_match('/SE 2.x/i',$agent, $match)) {
$browser='搜狗浏览器';
}elseif(preg_match('/NetCaptor\s([^\s;]+)/i', $agent, $match)){
$browser= '(IE ' .$match[1]. ') NetCaptor';    
}elseif(preg_match('/Lynx\/([^\s]+)/i', $agent, $match)){
$browser= 'Lynx '.$match[1];    
}elseif(preg_match('/MicroMessenger/i', $agent, $match)){
$browser= '微信浏览器 ';    
}elseif(preg_match('/Tencent/i', $agent, $match)){
$browser= 'QQ浏览器 ';    
}elseif(preg_match('/baidu/i', $agent, $match)){
$browser= '百度浏览器 ';    
}else{
$browser = 'Other';
}
return $browser;
}

$agent参数是用户的UA,也就是$_SERVER['HTTP_USER_AGENT']

UA的其他使用:
获取用户手机设备类型用户画像统计分析-php实用功能记录(五)
用户画像统计分析之获取访问用户的操作系统-php实用功能记录(六)


0 位网友评论:

欢迎来评论

请填写验证码