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
https://forums.phpfreaks.com/topic/101579-solved-get_browser/
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
https://forums.phpfreaks.com/topic/101579-solved-get_browser/#findComment-519624
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
https://forums.phpfreaks.com/topic/101579-solved-get_browser/#findComment-519632
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
https://forums.phpfreaks.com/topic/101579-solved-get_browser/#findComment-519639
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
https://forums.phpfreaks.com/topic/101579-solved-get_browser/#findComment-519640
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
https://forums.phpfreaks.com/topic/101579-solved-get_browser/#findComment-519662
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.