php获取IE浏览器版本函数

在php中我们要获取浏览器信息可以直接使用$userAgent = strtolower($_SERVER[\"HTTP_USER_AGENT\"]);然后再判断一下就可以判断用户浏览器版本或型号了,希望下面的实例对大家有所帮助.

下面笔者为各位介绍一款如何判断用户浏览器是不是IE6的php函数,如果是返回“真”,否则返回“假”.

实例代码如下:

  1. function isIE6() {
  2. $userAgent = strtolower($_SERVER["HTTP_USER_AGENT"]);
  3. //从HTTP_USER_AGENT字段中获取用户浏览器信息
  4. if (ereg("msie 6", $userAgent) || ereg("msie 5", $userAgent)) {
  5. return true;
  6. }
  7. return false;
  8. }

完整点的实例代码如下:

  1. function userBrowser(){
  2. $user_OSagent = $_SERVER['HTTP_USER_AGENT'];
  3. if(strpos($user_OSagent,"Maxthon") && strpos($user_OSagent,"MSIE")) {
  4. $visitor_browser ="Maxthon(Microsoft IE)";
  5. }elseif(strpos($user_OSagent,"Maxthon 2.0")) {
  6. $visitor_browser ="Maxthon 2.0";
  7. }elseif(strpos($user_OSagent,"Maxthon")) {
  8. $visitor_browser ="Maxthon";
  9. }elseif(strpos($user_OSagent,"MSIE 9.0")) {
  10. $visitor_browser ="MSIE 9.0";
  11. }elseif(strpos($user_OSagent,"MSIE 8.0")) {
  12. $visitor_browser ="MSIE 8.0";
  13. }elseif(strpos($user_OSagent,"MSIE 7.0")) {
  14. $visitor_browser ="MSIE 7.0";
  15. }elseif(strpos($user_OSagent,"MSIE 6.0")) {
  16. $visitor_browser ="MSIE 6.0";
  17. } elseif(strpos($user_OSagent,"MSIE 5.5")) {
  18. $visitor_browser ="MSIE 5.5";
  19. } elseif(strpos($user_OSagent,"MSIE 5.0")) {
  20. $visitor_browser ="MSIE 5.0";
  21. } elseif(strpos($user_OSagent,"MSIE 4.01")) {
  22. $visitor_browser ="MSIE 4.01";
  23. }elseif(strpos($user_OSagent,"MSIE")) {
  24. $visitor_browser ="MSIE 较高版本";
  25. }elseif(strpos($user_OSagent,"NetCaptor")) {
  26. $visitor_browser ="NetCaptor";
  27. } elseif(strpos($user_OSagent,"Netscape")) {
  28. $visitor_browser ="Netscape";
  29. }elseif(strpos($user_OSagent,"Chrome")) {
  30. $visitor_browser ="Chrome";
  31. } elseif(strpos($user_OSagent,"Lynx")) {
  32. $visitor_browser ="Lynx";
  33. } elseif(strpos($user_OSagent,"Opera")) {
  34. $visitor_browser ="Opera";
  35. } elseif(strpos($user_OSagent,"Konqueror")) {
  36. $visitor_browser ="Konqueror";
  37. } elseif(strpos($user_OSagent,"Mozilla/5.0")) {
  38. $visitor_browser ="Mozilla";
  39. } elseif(strpos($user_OSagent,"Firefox")) {
  40. $visitor_browser ="Firefox";
  41. }elseif(strpos($user_OSagent,"U")) {
  42. $visitor_browser ="Firefox";
  43. } else {
  44. $visitor_browser ="其它";
  45. }
  46. return $visitor_browser;
  47. }