Simple php browser detection

Hello, I’m writing about how to use php browser detection to have css php files that are completely dynamic getting rid of the need to have almost any hacks. However, I need a VERY simple php script that’ll detect simply the browser, version number, and os of a client. I don’t want to use somebody’s script that I find from google because I’m going to be redistributing this to other people, and that’s why I’m looking for help. The problem is that the $_SEVER[‘HTTP_USER_AGENT’] detects it as an entire string rather than just the browser type and other properties I need individually. I found got_browser but that doesn’t work without the browscap.ini file already installed in php, which isn’t an option for most people.

Can anybody please please help me find a simple way to test the browser?

Thanks,
Jeff :frowning:

otherwise can somebody help me get the code out of http://phpsniff.sourceforge.net/ that I need, I couldn’t get it to work :frowning:

otherwise can somebody help me get the code out of http://phpsniff.sourceforge.net/ that I need, I couldn’t get it to work

It won’t work as well as you might think. But here is an article that might help:

http://www.phpbuilder.com/columns/tim20000821.php3?page=2

I saw that, but I was just looking for browser detection, and the shortest possible method, that seems a bit excessive

anybody?

$browser = get_browser();
if ( $browser->browser == "IE" )
{
print ("Hellow You have IE");
}
if ( $browser->browser == "NS" )
{
print ("Hellow You have Netscape")
}
if ( $browser->browser == "FX" )
{
print ("OMG, FIREFOX, YOU THE MAN!! WAY TO GO!")
}

these are the shortcuts I know…

FireFox FX
Netscape NS
Mozilla MZ
Opera OP
microsoft internet explorer IE
galeon GA
phoenix PX
mozilla firebird FB
firebird FB
icab IC
lynx LX
links LI

I found that but whenever I use getbrowser it comes up with an error about the browscap ini directive not set, so I downloaded the php_browscap.ini file, and tried making a folder called extras in my php folder and linking to it both as extras/php_browscap.ini and C:\php\extras\php_browscap.ini. I have no clue on why I can’t get this function to work…

btw: nice example :slight_smile:

got the function to work now, but whenever I try your example it is just blank, but when I use php’s documentation’s example it works, I’ll play with it and hopefully get it :slight_smile: