Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Detect IE 11 or below
if (preg_match('~MSIE|Internet Explorer~i', $_SERVER['HTTP_USER_AGENT']) || (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0') !== false)) {
//is IE 11 or below
Copy link

neenjaw commented Jun 23, 2018

Nice snippet, thanks!

Copy link

Works thanks

Copy link

koran2019 commented Sep 26, 2019

Not worked on IE with touchscreen. Modify to support touchscreens:

if (preg_match('~MSIE|Internet Explorer~i', $_SERVER['HTTP_USER_AGENT']) || preg_match('~Trident/7.0(; Touch)?; rv:11.0~',$_SERVER['HTTP_USER_AGENT'])) {
//is IE 11 or below

Copy link

Thanks 👍

Copy link

Thanks 👏

Copy link

The solution by @koran2019 got me slightly closer to the issue, but I had additional LCTE string in my user string (Lenovo touchscreen laptop) as so:

~Trident/7.0; Touch; LCTE; rv:11.0~

Adding a general wildcard helped here:

$badBrowser = 
      preg_match('~MSIE|Internet Explorer~i', $_SERVER['HTTP_USER_AGENT']) || 
      preg_match('~Trident/7.0(.*)?; rv:11.0~', $_SERVER['HTTP_USER_AGENT']);

For anyone who is still having issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment