When we received a report that a problem occurred in the Internet Explorer 11 (hereinafter referred to as IE11) browser on a system that had been running without problems until now, we found that the user agent format had been changed in IE11 and the browser judgment process was treated as an "unknown browser".
Until now, I had been using the browser version token of the user agent (the part where UA says "MSIE 9.0" or something like that) to obtain the IE browser judgment and IE version, but from IE11, this browser version token has disappeared, and a new revision token called "rv" has been provided (*IE11 standard browser mode).
In order to uniquely judge IE, including IE11 in the future, the existence confirmation of the browser engine Trident token (the part where "Trident/7.0" in UA is written) must also be determined by the OR condition.
UserAgent in IE11
- [Browser mode: standard] Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko
- [Browser mode: compatibility display] Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0)
The problem is IE's compatible display mode. IE's compatibility display mode is a feature introduced from IE9, but if this mode is used, the UA browser version token will be IE7 in all current IEs. In order to accurately judge IE11 when displaying compatibility, it is necessary to first determine the trident token, and if the trident version is 7.0 or higher, it is judged as IE11 and the browser version is obtained from the revision token, and the other version is obtained from the browser version token. In addition, processing for IE9 and IE10, which have a lower compatibility display mode than IE11, is also required.
Also, IE7 and below do not have a trident token, so a separate judgment process for IE7 is also required... (No, it's like harassment...).
As a test, I modified the unique client device judgment processing (PHP) used in this DEVLAB to support IE11.
First of all, the contents of the IE judgment processing so far.
[php] $ua = $_SERVER['HTTP_USER_AGENT']; $results['browser'] = ''; $results['version'] = ''; if (preg_match('/(MSIE \d{1,}?(. \d{1,}?) {1,}?;) /', $ua, $mtcs)) { $results['browser'] = 'msie'; list(, $vstr) = explode(' ', str_replace(';', '', $mtcs[0])); $results['version'] = $vstr; } [/php]
I changed this as follows.
The processing of the version number extractor was also a bit lame, so I fixed it.
[php] $ua = $_SERVER['HTTP_USER_AGENT']; $results['browser'] = ''; $results['version'] = ''; if (preg_match('/Trident\/(\d{1,}(.\d{1,}){1,}?) /i', $ua, $mtcs)) { $results['browser'] = 'msie'; if ((float)$mtcs[1] >= 7) { if (preg_match('/rv:(\d{1,}(.\d{1,}){1,}?) /i', $ua, $mtcs)) { $results['version'] = (float)$mtcs[1]; } else { $results['version'] = 11.0; } } elseif ((float)$mtcs[1] >= 6) { $results['version'] = 10.0; } elseif ((float)$mtcs[1] >= 5) { $results['version'] = 9.0; } elseif ((float)$mtcs[1] >= 4) { $results['version'] = 8.0; } } if (empty($results['browser'])) { if (preg_match('/MSIE\s(\d{1,}(.\d{1,}){1,}?); /i', $ua, $mtcs)) { $results['browser'] = 'msie'; $results['version'] = (float)$mtcs[1]; } } [/php]
I don't like it that there are so many steps just to judge IE...
To be honest, I would like you to stop changing the format of UserAgent with upgrades other than changes to the browser engine or major fundamental specification changes...