Skip to content

Instantly share code, notes, and snippets.

@douglascabral
Created April 3, 2017 12:08
Show Gist options
  • Save douglascabral/6ee44fc02218936d32741f7c7f7f157e to your computer and use it in GitHub Desktop.
Save douglascabral/6ee44fc02218936d32741f7c7f7f157e to your computer and use it in GitHub Desktop.
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
}
@garethmorgans
Copy link

Thanks 👏

@ohepworthbell
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