Note that there are some explanatory texts on larger screens.

plurals
  1. POIE 9 user agent is lying! Weirdest damn thing I've ever seen
    primarykey
    data
    text
    <p>So here's my quandary. I have a website that's very sensative to user agents. It is absolutely imparative that the correct user agent is sent to the site, or the site will not work for that user. Site works fine, unless a user is directed there via permanant redirect.</p> <p>That's where it gets interesting. See, Firefox and Chrome have no issues. But IE starts lying about what version of the browser you're using the minute it sees the status and the domain change. I have a client (a very big slow client) linking my site from the outside via permanant redirect. And I don't think this client has the ability to change that right now. So I'm stuck with it, and my browser detection goes wonky when IE goes from being:</p> <blockquote> <p>Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)</p> </blockquote> <p>to:</p> <blockquote> <p>Mozilla/4.0 compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3</p> </blockquote> <p>Some things I've tried: Added the meta tag that changes the rendering engine:</p> <pre><code>&lt;meta content="IE=7" http-equiv="X-UA-Compatible" /&gt; </code></pre> <p>Works in IE 8, but 9 ignores it. Tried detecting different versions of .net framework, but it's not always reliable. Tried using a canvas tag in Javascript, but that only broke it in IE 7 and sometimes 8.</p> <p>I'm thinking there has to be some kind of header I can push to it, but I don't know of any.</p> <p>Has anyone seen this before? Is there a functional workaround?</p> <p><strong>Edit:</strong> Someone suggested modernizer. That's an awesome idea. </p> <p>The other thing I did to resolve this was rewrite my browser detection script.</p> <p>Here it is, in case anyone ever finds themselves in with a similar problem: It's dirty, but it works.</p> <pre><code>function getBrowser() { //shamlessly "borrowed" from the manual at http://php.net/manual/en/function.get-browser.php //Needed some cleanup. //Still needs some cleanup $u_agent = $_SERVER['HTTP_USER_AGENT']; $bname = 'Unknown'; $platform = 'Unknown'; $version = ""; $xploded = explode(';',$u_agent); //pretty($xploded); // finally get the correct version number $known = array('Version', $ub, 'other'); $pattern = '#(?&lt;browser&gt;' . join('|', $known) . ')[/ ]+(?&lt;version&gt;[0-9.|a-zA-Z.]*)#'; if (!preg_match_all($pattern, $u_agent, $matches)) { // we have no matching number just continue } // see how many we have $i = count($matches['browser']); if ($i != 1) { //we will have two since we are not using 'other' argument yet //see if version is before or after the name if (strripos($u_agent, "Version") &lt; strripos($u_agent, $ub)) { $version = $matches['version'][0]; } else { $version = $matches['version'][1]; } } else { $version = $matches['version'][0]; } // check if wfunction getBrowser() { $u_agent = $_SERVER['HTTP_USER_AGENT']; $bname = 'Unknown'; $platform = 'Unknown'; $version = ""; //First get the platform? if (preg_match('/linux/i', $u_agent)) { $platform = 'linux'; } elseif (preg_match('/macintosh|mac os x/i', $u_agent)) { $platform = 'mac'; } elseif (preg_match('/windows|win32/i', $u_agent)) { $platform = 'windows'; } // Next get the name of the useragent yes seperately and for good reason if (preg_match('/MSIE/i', $u_agent) &amp;&amp; !preg_match('/Opera/i', $u_agent)) { $bname = 'Internet Explorer'; $ub = "MSIE"; } elseif (preg_match('/Firefox/i', $u_agent)) { $bname = 'Mozilla Firefox'; $ub = "Firefox"; } elseif (preg_match('/Chrome/i', $u_agent)) { $bname = 'Google Chrome'; $ub = "Chrome"; } elseif (preg_match('/Safari/i', $u_agent)) { $bname = 'Apple Safari'; $ub = "Safari"; } elseif (preg_match('/Opera/i', $u_agent)) { $bname = 'Opera'; $ub = "Opera"; } elseif (preg_match('/Netscape/i', $u_agent)) { $bname = 'Netscape'; $ub = "Netscape"; } // finally get the correct version number $known = array('Version', $ub, 'other'); $pattern = '#(?&lt;browser&gt;' . join('|', $known) . ')[/ ]+(?&lt;version&gt;[0-9.|a-zA-Z.]*)#'; if (!preg_match_all($pattern, $u_agent, $matches)) { // we have no matching number just continue } // see how many we have $i = count($matches['browser']); if ($i != 1) { //we will have two since we are not using 'other' argument yet //see if version is before or after the name if (strripos($u_agent, "Version") &lt; strripos($u_agent, $ub)) { $version = $matches['version'][0]; } else { $version = $matches['version'][1]; } } else { $version = $matches['version'][0]; } // check if we have a number if ($version == null || $version == "") { $version = "?"; } $bname = strtolower($bname); $windows_version = floatval(trim(str_ireplace('Windows NT','',$xploded[2]) )); //Sloppy hack for dealing with IE 9, specifically. $trial = intval($version); if($windows_version == 6.1 &amp;&amp; $bname == 'internet explorer' &amp;&amp; $trial == 7){ //the browser is lying to you. //print "We are being lied to&lt;br&gt;"; $version = 9.0; } //print 'windows version is......'.$windows_version.'&lt;br&gt;'; //print 'browser id is......'.$bname.'&lt;br&gt;'; //print 'raw version is......'.$version.'&lt;br&gt;'; return array( 'test'=&gt;'test', 'name' =&gt; $bname, 'version' =&gt; intval($version) ); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload