Php functions for obtaining IE browser versions

Source: Internet
Author: User
Tags ereg
To obtain browser information in php, you can directly use $ userAgentstrtolower ($ _ SERVER [& quot; HTTP_USER_AGENT & quot;]). then, you can judge your browser.

To obtain browser information in php, use $ userAgent = strtolower ($ _ SERVER [\ "HTTP_USER_AGENT \"]). then you can judge the version or model of your browser. I hope the following instances will help you.

Next I will introduce you to a php function that determines whether your browser is IE6. if "true" is returned, otherwise "false" is returned ".

The instance code is as follows:

  1. Function isIE6 (){
  2. $ UserAgent = strtolower ($ _ SERVER ["HTTP_USER_AGENT"]);
  3. // Obtain the user's browser information from the HTTP_USER_AGENT field
  4. If (ereg ("msie 6", $ userAgent) | ereg ("msie 5", $ userAgent )){
  5. Return true;
  6. }
  7. Return false;
  8. }

The complete instance code is as follows:

  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 = "higher MSIE version ";
  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 = "others ";
  45. }
  46. Return $ visitor_browser;
  47. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.