Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.5.2

Bug #18744 ie detection flawed, have fix
Submitted: 2011-08-19 04:45 UTC
From: jvermette Assigned:
Status: Analyzed Package: Net_UserAgent_Detect (version 2.5.2)
PHP Version: 5.2.12 OS: linux
Roadmaps: (Not assigned)    
Subscription  


 [2011-08-19 04:45 UTC] jvermette (josh vermette)
Description: ------------ IE detection has some flaws. This browser string (from actual client reports): === Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR\ 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; Media Center PC 4.0; MS-RTC LM 8) === reports as ie6 and no higher. This is because it contains the string "msie 6". I have a fix based on a preg match of the msie number and some simple math. The whole thing ends up being more efficient and also (because why the heck not) supports detection of MSIE > 9. Revised code, along with original for reference, follows. /* FIX */ preg_match("#msie ([.0-9]+)#i", $agt, $matches); $ieNum = floatval($matches[1]); $browser['ie5_5'] = ($ieNum == 5.5); $browser['ie5_5up'] = ($ieNum >= 5.5); $browser['belowie6']= ($ieNum < 6); for ($i = 5 ; $i < 12 ; $i++) { $browser['ie'.$i] = ($ieNum >= $i) && ($ieNum < ($i+1)); $browser['ie'.$i.'up'] = ($ieNum >= $i); } if (strpos($agt, 'trident/4')) { $browser['ie7'] = false; //ie7 with trident is not ie7 $browser['ie8tr'] = ($ieNum == 7); //ie8tr is ie7 with trident } else { $browser['ie8tr'] = false; } /* ORIG $browser['ie5'] = $browser['ie4up'] && (strpos($agt, 'msie 5') !== false); $browser['ie5_5'] = $browser['ie4up'] && (strpos($agt, 'msie 5.5') !== false); $browser['ie5up'] = $browser['ie4up'] && !$browser['ie3'] && !$browser['ie4']; $browser['ie5_5up'] = $browser['ie5up'] && !$browser['ie5']; $browser['ie6'] = strpos($agt, 'msie 6') !== false; $browser['ie6up'] = $browser['ie5up'] && !$browser['ie5'] && !$browser['ie5_5']; $browser['ie7'] = strpos($agt, 'msie 7') && !strpos($agt,'trident/4'); $browser['ie7up'] = $browser['ie6up'] && (!$browser['ie6'] || $browser['ie7']); $browser['ie8tr'] = strpos($agt, 'msie 7') && strpos($agt,'trident/4') !== false; $browser['ie8'] = strpos($agt, 'msie 8') !== false; $browser['ie8up'] = $browser['ie7up'] && (!$browser['ie7'] || $browser['ie8']); $browser['ie9'] = strpos($agt, 'msie 9') !== false; $browser['ie9up'] = $browser['ie8up'] && (!$browser['ie8'] || $browser['ie9']); $browser['belowie6']= $browser['ie'] && !$browser['ie6up']; END FIX */ Test script: --------------- simply "detect" the browser string above Expected result: ---------------- should detect ie6up, ie7up, ie8up, and ie8 Actual result: -------------- it detects ie6 and no higher

Comments

 [2014-03-30 18:32 UTC] doconnor (Daniel O'Connor)
-Status: Open +Status: Analyzed
Can I get you to fork + make a pull request for this?
 [2014-03-31 12:56 UTC] jvermette (josh vermette)
Sorry Daniel, that was a long time ago by now and I'm not currently in a situation where I'm able to do that.