Jump to content

[SOLVED] get_browser


djpic

Recommended Posts

I have a question about the get browser function.  I am currently using the $_SERVER['HTTP_USER_AGENT'] but that just outputs a long variable: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3  << example

 

All I need is the browser name and version number.  Formated like this if possible: IE 7, Firefox 2, etc.  I read up on the get_browser function but I want to know how I can get the information from just that browser.  The documentation says it returns an array:

Array

(

    [browser_name_regex] => ^mozilla/5\.0 (windows; .; windows nt 5\.1; .*rv:.*) gecko/.* firefox/0\.9.*$

    [browser_name_pattern] => Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9*

    [parent] => Firefox 0.9

    [platform] => WinXP

    [browser] => Firefox

    [version] => 0.9

    [majorver] => 0

    [minorver] => 9

    [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] =>

)

 

But how do I just pull the [browser], [version], [platform] from that statement?

 

Here is the documentation for the get_browser function:

http://us3.php.net/manual/en/function.get-browser.php

 

Thanks.

Link to comment
Share on other sites

$browser = get_browser();
echo $browser->browser .'<br>'. $browser->version .'<br>'. $browser->platform;

 

From what I've read this function should be avoided because it it slow.

That doesn't return anything.

Link to comment
Share on other sites

Error reporting is your friend.

 

Try this:

 

<?php

if( !ini_get('browscap') )
    echo 'Can\'t use get_browser with current ini settings';
else {
$browser = get_browser();
echo $browser->browser .'<br>'. $browser->version .'<br>'. $browser->platform;
}

?>

Link to comment
Share on other sites

Keep in mind that get_browser() loads the ~ 200-400kb browscap.ini file each time, thus slowing down the script a great deal. And newer browsers will only be recognized if the browscap.ini is up to date (that requires a lot of updating from your side). However, IF you go with it, you should not run i more than once per user/session - if you need the output on multiple pages, I would store it in a session.

Link to comment
Share on other sites

Error reporting is your friend.

 

Try this:

 

<?php

if( !ini_get('browscap') )
    echo 'Can\'t use get_browser with current ini settings';
else {
$browser = get_browser();
echo $browser->browser .'<br>'. $browser->version .'<br>'. $browser->platform;
}

?>

 

Ok,

Can't use get_browser with current ini settings
, how do I fix that.  I have full access to the server.  I am running Fedora 8.
Link to comment
Share on other sites

Keep in mind that get_browser() loads the ~ 200-400kb browscap.ini file each time, thus slowing down the script a great deal. And newer browsers will only be recognized if the browscap.ini is up to date (that requires a lot of updating from your side). However, IF you go with it, you should not run i more than once per user/session - if you need the output on multiple pages, I would store it in a session.

 

Is there any other way to get that information with placing that load on the server?

Link to comment
Share on other sites

Is there any other way to get that information with placing that load on the server?

 

Use regex to parse the HTTP_USER_AGENT variable.

 

Ok,

Can't use get_browser with current ini settings
, how do I fix that.  I have full access to the server.  I am running Fedora 8.

 

There's plenty out there that tells you how to fix that.. just look up browscap

http://garetjax.info/projects/browscap/

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.