30 Jan 2014
Use PHP to Detect Internet Explorer 11 and Below
As I’ve mentioned before, Microsoft dropped conditional comment support in Internet Explorer 10 (and didn’t bring it back in IE 11). This means that you must use JavaScript or PHP to detect Internet Explorer 10 (IE10) or Internet Explorer 11 (IE11), which is a darn shame.
It’s pretty easy to do, however. Especially if you are targeting ALL versions of Internet Explorer. Here’s what I currently do:
if (preg_match('~MSIE|Internet Explorer~i', $_SERVER['HTTP_USER_AGENT']) || (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0') !== false)) {
It’s simple and it works well. The first part targets IE10 and below, while the second targets the newer IE11 user agent. Modify as needed.
I think the more germane issue, is to detect for IE10 and above.
// IDENTIFY IE VERSIONS – returns ‘1’ if true
$isIE10 = (preg_match(‘/(?i)msie [10]/’,$_SERVER[‘HTTP_USER_AGENT’]));
$isIE11UP = (preg_match(‘/(?i)trident/[7-9]/’,$_SERVER[‘HTTP_USER_AGENT’]));
$isIE10UP = ($isIE10 == 1 || $isIE11UP == 1 ? 1 : 0);
Excellent, worked perfectly, thank you very much