Skip to content

Instantly share code, notes, and snippets.

Created April 3, 2017 12:08
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
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

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