Jump to content

Archived

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

birdie

Browser detection

Recommended Posts

Hi, i know $_SERVER['http_user_agent'] provides 'browser' detection but it just doesnt work simply.

Is there any way you can basically but this variable or another 1 which can do a relatively similiar action.

Example of the script

[code]
$browser = $_SERVER['http_user_agent'];
if(eregi('Firefox', $browser))
{
$sql = "UPDATE sitestats_browser SET firefox='$firefox'";
}
elseif(eregi('MSIE', $browser))
{
$sql = "UPDATE sitestats_browser SET ie='$internetexplorer'";
}
else
{
$sql = "UPDATE sitestats_browser SET other='$other'";
}
[/code]

Well this doesnt work because there are different versions of firefox.

Any help please?

Share this post


Link to post
Share on other sites
Try the get_browser() function: [url=http://www.phpfreaks.com/phpmanual/page/function.get-browser.html]http://www.phpfreaks.com/phpmanual/page/function.get-browser.html[/url]

Share this post


Link to post
Share on other sites
[url=http://www.zytrax.com/tech/web/browser_ids.htm]http://www.zytrax.com/tech/web/browser_ids.htm[/url]

Have a look at the UA strings

Share this post


Link to post
Share on other sites
[code=php:0]
<?
$b = $_SERVER['HTTP_USER_AGENT'];
if(eregi('firefox', $b)) {
echo "got firefox";
}
elseif(eregi('MSIE', $b)) {
echo "got IE";
}
else { echo "Got other"; }
?>
[/code]

Just tried that real quick... It works fine... ( http://corbin-dev.no-ip.org/browser.php )

Share this post


Link to post
Share on other sites
wow thanks for the quick posts, i'll try them all out :-)

Share this post


Link to post
Share on other sites

×

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.