Sign in to follow this  
Matt

Get_browser In Various Browsers

Recommended Posts

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.

  1. Why does each browser output different elements of the array?
  2. Why does Internet Explorer output [browser_name_regex] as ^mozilla/.\.0 ?
  3. Why does Opera output [browser] as 'Default Browser'?

Thanks,

Matt

Share this post


Link to post
Share on other sites

  1. 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.
  2. 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.
  3. 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 by jcl

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this