Matt Posted September 4, 2006 Report Share Posted September 4, 2006 A sample php function:<?php$browser = get_browser(null, true);print_r($browser);?>The output in Firefox:Array ( [browser_name_regex] => ^mozilla/5\.0 (windows; .; windows nt 5\.1; .*; rv:1\.8.*) gecko/.*$ [browser_name_pattern] => Mozilla/5.0 (Windows; ?; Windows NT 5.1; *; rv:1.8*) Gecko/* [parent] => Mozilla 1.8 [platform] => WinXP [browser] => Mozilla [version] => 1.8 [majorver] => 1 [minorver] => 8 [css] => 2 [frames] => 1 [iframes] => 1 [tables] => 1 [cookies] => 1 [backgroundsounds] => [vbscript] => [javascript] => 1 [javaapplets] => 1 [activexcontrols] => [cdf] => [aol] => [beta] => 1 [win16] => [crawler] => [stripper] => [wap] => [netclr] => )Output from IE:Array ( [browser_name_regex] => ^mozilla/.\.0 (compatible; msie 6\.0.*;.*windows nt 5\.1.*\.net clr.*).*$ [browser_name_pattern] => Mozilla/?.0 (compatible; MSIE 6.0*;*Windows NT 5.1*.NET CLR*)* [parent] => IE 6.0 [platform] => WinXP [netclr] => 1 [browser] => IE [version] => 6.0 [majorver] => 6 [minorver] => 0 [css] => 2 [frames] => 1 [iframes] => 1 [tables] => 1 [cookies] => 1 [backgroundsounds] => 1 [vbscript] => 1 [javascript] => 1 [javaapplets] => 1 [activexcontrols] => 1 [cdf] => 1 [aol] => [beta] => [win16] => [crawler] => [stripper] => [wap] => [ak] => [sk] => )Output in Opera:Array ( [browser_name_regex] => ^.*$ [browser_name_pattern] => * [browser] => Default Browser [css] => 0 [frames] => [iframes] => [tables] => 1 [cookies] => [backgroundsounds] => [vbscript] => [javascript] => [javaapplets] => [activexcontrols] => [cdf] => [aol] => [beta] => [win16] => [crawler] => [stripper] => [wap] => [netclr] => )From this, I have a few questions.Why does each browser output different elements of the array?Why does Internet Explorer output [browser_name_regex] as ^mozilla/.\.0 ?Why does Opera output [browser] as 'Default Browser'?Thanks,Matt Quote Link to post Share on other sites
jcl Posted September 4, 2006 Report Share Posted September 4, 2006 (edited) get_browser() reads the entrails^WUser-Agent header sent by the browser and uses the local browscap.ini to construct a table describing the client and whether it supposedly supports some arbitrary features. It appears that entries in browscap.ini determine both the keys and values of the table, so the set of keys can be inconsistent between different clients. Hooray for PHP. The IE User-Agent string is something like "Mozilla/<version> (compatible; MSIE <version>; <system> <version>)" for historical reasons. I think it's supposed to be the version of Mozilla (read Netscape) with which IE is compatible. It's been stuck at Mozilla/4.0 since IE4 and I don't think it's ever been accurate. I would guess that the version of PHP you used doesn't recognize the User-Agent string Opera sent and so it returned in the default values. Reading the commentary for the function it looks like it's not an uncommon problem. Edited September 4, 2006 by jcl Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.