PHP简单判断当前使用的是什么浏览器,判断浏览器类型的方法,方便统计网站访问用户使用浏览器的比例。
判断浏览器类型方法
1 function userBrowser() { 2 $user_OSagent = $_SERVER['HTTP_USER_AGENT']; 3 4 if (strpos($user_OSagent, "Maxthon") && strpos($user_OSagent, "MSIE")) { 5 $visitor_browser = "Maxthon(Microsoft IE)"; 6 } elseif (strpos($user_OSagent, "Maxthon 2.0")) { 7 $visitor_browser = "Maxthon 2.0"; 8 } elseif (strpos($user_OSagent, "Maxthon")) { 9 $visitor_browser = "Maxthon"; 10 } elseif (strpos($user_OSagent, "MSIE 9.0")) { 11 $visitor_browser = "MSIE 9.0"; 12 } elseif (strpos($user_OSagent, "MSIE 8.0")) { 13 $visitor_browser = "MSIE 8.0"; 14 } elseif (strpos($user_OSagent, "MSIE 7.0")) { 15 $visitor_browser = "MSIE 7.0"; 16 } elseif (strpos($user_OSagent, "MSIE 6.0")) { 17 $visitor_browser = "MSIE 6.0"; 18 } elseif (strpos($user_OSagent, "MSIE 5.5")) { 19 $visitor_browser = "MSIE 5.5"; 20 } elseif (strpos($user_OSagent, "MSIE 5.0")) { 21 $visitor_browser = "MSIE 5.0"; 22 } elseif (strpos($user_OSagent, "MSIE 4.01")) { 23 $visitor_browser = "MSIE 4.01"; 24 } elseif (strpos($user_OSagent, "MSIE")) { 25 $visitor_browser = "MSIE 较高版本"; 26 } elseif (strpos($user_OSagent, "NetCaptor")) { 27 $visitor_browser = "NetCaptor"; 28 } elseif (strpos($user_OSagent, "Netscape")) { 29 $visitor_browser = "Netscape"; 30 } elseif (strpos($user_OSagent, "Chrome")) { 31 $visitor_browser = "Chrome"; 32 } elseif (strpos($user_OSagent, "Lynx")) { 33 $visitor_browser = "Lynx"; 34 } elseif (strpos($user_OSagent, "Opera")) { 35 $visitor_browser = "Opera"; 36 } elseif (strpos($user_OSagent, "Konqueror")) { 37 $visitor_browser = "Konqueror"; 38 } elseif (strpos($user_OSagent, "Mozilla/5.0")) { 39 $visitor_browser = "Mozilla"; 40 } elseif (strpos($user_OSagent, "Firefox")) { 41 $visitor_browser = "Firefox"; 42 } elseif (strpos($user_OSagent, "U")) { 43 $visitor_browser = "Firefox"; 44 } else { 45 $visitor_browser = "其它"; 46 } 47 return $visitor_browser; 48 }
直接调用 userBrowser()
echo "您现在使用的浏览器是:" . userBrowser();?>
本文转自:https://www.sucaihuo.com/php/220.html 转载请注明出处!