Skip to main content

How to detect IE (Internet Explorer) 10 & 11 using PHP

If you need to detect Internet Explorer, specifically browser version 10 or 11 using PHP, then you can use the following PHP code to detect the Internet Explorer version. This script works with all IE  versions, i.e., 8, 9, 10 and 11.

Using the conditional HTML comments can only detect IE 6/7/8/9 but they fail to detect IE 10 & 11. Because Microsoft has stopped sending "IE" or "MSIE" strings in the header information for IE 10 and IE 11 browser versions. So it is highly recommended to use a server side programming like PHP to detect the browser's User Agent value from the HTTP header request. Continue reading below to see how you can use a simple PHP code to detect Internet Explorer version using PHP code.


PHP IE Browser Detection code

Using the below PHP IE detection code, you can find if a request is coming from Internet Explorer or any other browser. You can also add extra code to parse the IE version if need be.

For example, if you have a need of adding a custom CSS stylesheet rules for Internet Explorer versions, to have your webpage backward compatible, then using the example below you can add an extra class "ie" to your


tag. Later add some CSS rules to have different treatment for any child tag in the body.


if (isset($_SERVER['HTTP_USER_AGENT']) && ( (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false ) || (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0') !== false) ) ){ 
  // write you code here for IE   
  // e.g. add classes to 

or tag. i.e. // then write custom CSS rules. e.g. .ie h1{font-size:16px;} }

For more reading and advanced use of browser detection, you can learn more about an inbuilt PHP function get_browser(). Also please notice, the get_browser() function is considerably slow and may affect web server performance if running on PHP 5.

See some benchmark results here -

This tutorial is focused on IE detection in PHP. But if the scope of your requirements is wider and you wish to include all browsers detection, then get_browser() is recommended to use. Please make sure that you're running on PHP 7. The get_browser() function performs better on PHP 7.