Home > Article > Backend Development > PHP code to determine browser type
There are more and more types of browsers now. It is inevitable to consider compatibility issues when programming. Sometimes it is necessary to load different style types based on the browser type. The code in this article can determine IE6, IE7, IE8, firefox, chrome and other browsers.
The following code uses $_SERVER["HTTP_USER_AGENT"] for judgment. It can judge mainstream browsers such as IE6, IE7, IE8, firefox, and chrome. <?php //检测浏览器类型 //site http://bbs.it-home.org if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE8.0")) echo"InternetExplorer8.0"; elseif(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE7.0")) echo"InternetExplorer7.0"; elseif(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE6.0")) echo"InternetExplorer6.0"; elseif(strpos($_SERVER["HTTP_USER_AGENT"],"Firefox/17")) echo"Firefox17"; elseif(strpos($_SERVER["HTTP_USER_AGENT"],"Firefox/16")) echo"Firefox16"; elseif(strpos($_SERVER["HTTP_USER_AGENT"],"Chrome")) echo"GoogleChrome"; elseif(strpos($_SERVER["HTTP_USER_AGENT"],"Safari")) echo"Safari"; elseif(strpos($_SERVER["HTTP_USER_AGENT"],"Opera")) echo"Opera"; elseecho$_SERVER["HTTP_USER_AGENT"]; ?> For articles on browser type detection, you can also read these two articles: php Get the code of the visitor’s browser php code to determine browser type, browser language and other information |