$_SERVER[‘user-agent’] to check for IE (including IE 11)


ie11 missing user-agent

Summary: The user agent for IE 11 does not contain MSIE any more, which is a tactic deliberately set by Microsoft IE team.

Although browser sniffing is NOT considered as a best practice for web development, it is sometimes a must owing to various practical reasons. Recently, I need to hide a certain warning message if the browser is IE. However, the server-side script to test for IE is not as simple as before IE 11 as the IE team at Microsoft deliberately hide the MSIE string in the user-agent.

The Temporary Solution

If you use sever-side script to detect whether the browser is IE, you will need to test for either Trident (for IE 8+) or MSIE (for IE 10-) as below:

<?php

if(!(isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))):

?>

 

Support website running for FREE, thanks!

If you find this post helpful and if you are thinking of buying from Amazon, please support the running cost of this website at no extra cost to you by searching and buying through the search box below. Thank you very much for your help!

Edward Chung

Edward Chung aspires to become a full-stack web developer and project manager. In the quest to become a more competent professional, Edward studied for and passed the PMP Certification, ITIL v3 Foundation Certification, PMI-ACP Certification and Zend PHP Certification. Edward shares his certification experience and resources here in the hope of helping others who are pursuing these certification exams to achieve exam success.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *