php获取浏览器版本
解决方法:
$agent = $_SERVER['HTTP_USER_AGENT'];
$browser = '';
$browser_ver = '';
if(preg_match('/OmniWeb\/(v*)([^\s|;]+)/i', $agent, $return)){
$browser = 'OmniWeb';
$browser_ver = $return[2];
}
if(preg_match('/Netscape([\d]*)\/([^\s]+)/i', $agent, $return)){
$browser = 'Netscape';
$browser_ver = $return[2];
}
if(preg_match('/safari\/([^\s]+)/i', $agent, $return)){
$browser = 'Safari';
$browser_ver = $return[1];
}
if(preg_match('/Chrome\/([^\s]+)/i', $agent, $return)){
$browser = 'Chrome';
$browser_ver = $return[1];
}
if(preg_match('/MSIE\s([^\s|;]+)/i', $agent, $return)){
$browser = 'Internet Explorer';
$browser_ver = $return[1];
}
if(preg_match('/Opera[\s|\/]([^\s]+)/i', $agent, $return)){
$browser = 'Opera';
$browser_ver = $return[1];
}
if(preg_match('/NetCaptor\s([^\s|;]+)/i', $agent, $return)){
$browser = '(Internet Explorer ' .$browser_ver. ') NetCaptor';
$browser_ver = $return[1];
}
if(preg_match('/Maxthon/i', $agent, $return)){
$browser = '(Internet Explorer ' .$browser_ver. ') Maxthon';
$browser_ver = '';
}
if(preg_match('/360SE/i', $agent, $return)){
$browser = '(Internet Explorer ' .$browser_ver. ') 360SE';
$browser_ver = '';
}
if(preg_match('/SE 2.x/i', $agent, $return)){
$browser = '(Internet Explorer ' .$browser_ver. ') sougou';
$browser_ver = '';
}
if(preg_match('/FireFox\/([^\s]+)/i', $agent, $return)){
$browser = 'FireFox';
$browser_ver = $return[1];
}
if(preg_match('/Lynx\/([^\s]+)/i', $agent, $return)){
$browser = 'Lynx';
$browser_ver = $return[1];
}
echo $browser.':'.$browser_ver;
结果:
Chrome:68.0.3440.106