Detect if any kind of IE (MSIE)
The request to block all versions of Microsoft Internet Explorer while accommodating modern browsers presents a specific detection challenge rooted in how the user agent string evolved. The core issue you identified is accurate: Internet Explorer 10 and 11 stopped including the literal "MSIE" token in their user agent strings to avoid being flagged as legacy software by web applications expecting older behavior. Instead, they masqueraded as Edge (or Chromium-based Edge in the case of IE11 in compatibility mode).
To implement a robust block, you must look beyond simple string matching for "MSIE". You need to handle three distinct scenarios:
- Legacy MSIE: Versions 0 through 9 and 10/11 running in compatibility mode.
- Modern Edge (Chromium): The current standard successor.
- Edge Legacy: The old Edge based on EdgeHTML, which often includes "Trident" in its engine but not always "MSIE".
Detecting Legacy Internet Explorer
The most reliable method for detecting legacy IE across all versions, including the modern ones that hide their identity, relies on checking for the presence of Trident. This is the rendering engine name used by Internet Explorer. However, simply checking for "Trident" isn't enough because Microsoft Edge (Chromium) does not use Trident; it uses Blink or WebKit.
If you are using JavaScript to block access, inspecting the navigator.userAgent string is the standard approach. You must look for the specific sequence MSIE to catch versions up to 10, and then check for Trident specifically combined with a version number logic that excludes modern Edge.
Here is a robust pattern using vanilla JavaScript:
function isLegacyIE() {
// Check for old IE (MSIE token present)
if (navigator.userAgent.indexOf("MSIE") > -1) {
return true;
}
// Check for Trident-based browsers (IE8-11) but exclude modern Edge
// Modern Edge contains "Edg/" and usually lacks "Trident" in the main user agent,
// though some legacy configs might differ. The safest bet is checking for "Trident"
// without the presence of "Edge".
if (navigator.userAgent.indexOf("Trident") > -1 &&
navigator.userAgent.indexOf("Edg") === -1) {
return true;
}
return false;
}
if (isLegacyIE()) {
alert("Internet Explorer is no longer supported. Please use a modern browser.");
// Redirect logic here, e.g., window.location.href = "/modern-browser-needed";
}
Handling the User Agent Evolution
The snippet you provided initially checks for MSIE. This works perfectly for IE6 through IE10. However, it fails silently for IE11 and modern Edge unless you add the logic for "Trident".
The MSDN documentation you referenced highlights that starting with version 10, the user agent string format changed to mimic Chrome or Firefox to ensure compatibility. This means a naive check like indexOf("MSIE") will return -1 (not found) for IE11 running in standard mode, even though it is still Internet Explorer under the hood.
If you are using jQuery, the library's own $.browser property has deprecated support for detecting these nuances accurately in newer versions of jQuery due to its reliance on outdated detection methods. Relying solely on $.browser.msie is risky because it may not correctly identify IE11 or Edge variants without additional configuration.
Server-Side Detection with PHP
If you prefer handling this logic on the server side, PHP provides direct access to the user agent string via the $_SERVER['HTTP_USER_AGENT'] variable. This avoids client-side obfuscation issues where a script might try to spoof the browser.
<?php
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$isIE = false;
// Check for MSIE (IE6-10)
if (strpos($userAgent, 'MSIE') !== false) {
$isIE = true;
}
// Check for Trident without Edge (IE8-11)
elseif (strpos($userAgent, 'Trident/') !== false && strpos($userAgent, 'Edg') === false) {
$isIE = true;
}
if ($isIE) {
// Redirect or show warning
header("Location: /not-ie-supported");
exit();
}
?>
Why This Approach Matters
The trade-off here is between strict blocking and user experience. By explicitly checking for Trident while ensuring Edg is absent, you catch the "hidden" IE versions that mimic other browsers. The primary pitfall to avoid is assuming that a missing "MSIE" string means the browser is safe. A developer might mistakenly think modern Edge is blocked by your code when it actually isn't, or worse, they might allow IE11 through because their regex didn't account for the engine change.
Ensuring your detection logic covers both the legacy token and the engine identifier guarantees that no version of Microsoft's Internet Explorer can bypass your security policy. For teams maintaining Laravel applications, integrating this check into middleware ensures that even if a user attempts to load the site via an outdated browser, they are intercepted before rendering any views.