php简单判断当前使用的是什么浏览器,判断浏览器类型的方法,方便统计网站访问用户使用浏览器的比例。
判断浏览器类型方法一
function urbrowr() { $ur_osagent = $_rver['http_ur_agent']; if (strpos($ur_osagent, "maxthon") && strpos($ur_osagent, "msie")) { $visitor_browr = "maxthon(microsoft ie)"; } elif (strpos($ur_osagent, "maxthon 2.0")) { $visitor_browr = "maxthon 2.0教学实施"; } elif (strpos($ur_osagent, "maxthon")) { $visitor_browr = "maxthon"; } elif (strpos($ur_osagent, "msie 9.0")) { $visitor_browr = "msie 9.0"; } elif (strpos($ur_osagent, "msie 8.0")) { $visitor_browr = "msie 8.0"; } elif (strpos($ur_osagent, "msie 7.0")) { $visitor_browr = "msie 7.0"; } elif (strpos($ur_osagent, "msie 6.0")) { $visitor_browr = "msie 6.0"; } elif (strpos($ur_osagent, "msie 5.5")) { $visitor_browr = "msie 5.5"; } elif (strpos($ur_osagent, "msie 5.0")) { $visitor_browr = "msie 5.0"; } elif (strpos($ur_osagent, "msie 4.01"))佳能 尼康 { $visitor_browr = "msie 4.01"; } elif (strpos($ur_osagent, "msie"))indicate是什么意思 { $visitor_browr = "msie 较高版本"; } elif (strpos($ur_osagent, "netcaptor")) { $visitor_browr = "netcaptor"; } elif (strpos($ur_osagent, "netscape")) { $visitor_browr = "netscape"; } elif (strpos($ur_osagent, "chrome")) { $visitor_browr = "chrome"; } elif (strpos($u想学会计r_osagent, "lynx")) { $visitor_browr = "lynx"; } elif (strpos($ur_osagent, "opera")) { $visitor_browr = "opera"; } elif (strpos($ur_osagent, "konqueror")) { $visitor_browr = "konqueror"; } elif (strpos($ur_osagent, "mozilla/5.0")) { $visitor_browr = "mozilla"; } elif (strpos($ur_osagent, "firefox")) { $visitor_browr = "firefox"; } elif (strpos($ur_osagent, "u")) { $visitor_browr = "firefox"; } el { $visitor_browr = "其它"; } return $visitor_browr; }
方法二
下面这个是php通过正则匹配的,理论上效率不如上面的方法一, 大家可以根据需要使用。
private function getbrowr(){$flag=$_rver['http_ur_agent'];$para=array();// 检查操作系统if(preg_match('/windows[\d\. \w]*/',$flag, $match)) $para['os']=$match[0];if(preg_match('/chrome\/[\d\.\w]*/',$flag, $match)){// 检查chrome$para['browr']=$match[0];}elif(preg_match('/safari\/[\d\.\w]*/',$flag, $match)){// 检查safari$para['browr']=$match[0];}elif(preg_match('/msie [\d\.\w]*/',$flag, $match)){// ie$para['browr']=$match[0];}elif(preg_match('/opera\/[\d\.\w]*/',$flag, $match)){// opera$para['browr']=$match[0];}elif(preg_match('/firefox\/[\d\.\w]*/',$flag, $match)){// firefox$para['browr']=$match[0];}elif(preg_match('/omniweb\/(v*)([^\s|;]+)/i',$flag, $match)){//omniweb$para['browr']=$match[2];}elif(preg_match('/netscape([\d]*)\/([^\s]+)/i',$flag, $match)){//netscape$para['browr']=$match[2];}elif(preg_match('/lynx\/([^\s]+)/i',$flag, $match)){//lynx$para['browr']=$match[1];}elif(preg_match('/360/i',$flag, $match)){//360$para['browr']='360安全浏览器';}elif(preg_match('/ 2.x/i',$flag, $match)) {//搜狗$para['browr']='搜狗浏览器';}el{$para['browr']='unkown';}return $para;}
保存$para即可
php判断浏览器是不是ie
1、$_rver[‘http_ur_agent’]和strpos
2、打印结果
谷歌:
“mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.古代关于爱情的诗36 (khtml, like gecko) chrome/59.0.3071.86 safari/537.36”
火狐:
“mozilla/5.0 (windows nt 10.0; wow64; rv:53.0) gecko/20100101 firefox/53.0”
ie:
“mozilla/5.0 (windows nt 10.0; wow64; trident/7.0; rv:11.0) like gecko”
3、php控制器中
网上说用判断ua中是否有msie,然而并没有,用triden判断也可以的。
public function isie() { $isie = strpos($_rver['http_ur_agent'],"triden"); return $isie; }
总结
以上所述是www.887551.com给大家介绍的php判断当前使用的是什么浏览器(推荐),希望对大家有所帮助!
本文发布于:2023-04-08 08:03:55,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/f2c792b71cdceb22b96449b0dbde79e1.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:PHP判断当前使用的是什么浏览器(推荐).doc
本文 PDF 下载地址:PHP判断当前使用的是什么浏览器(推荐).pdf
留言与评论(共有 0 条评论) |