Quick Browser Detection

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Quick Browser Detection

Post by Todd_Z »

What is the fastest way to detect the user's Browser. I am really only interested in detecting the big names - IE5, IE6, Fx, Netscape, AOL, etc.

I am looking for the most compact script in this case.

Thanks in advance.
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

some javascript will do. :)
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

I need the answer in my php script, js won't help here.

I am trying get_browser(), but when I try ini_set( "browscap", "php_browscap.ini" ), the value still appears to be empty. Any ideas?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you could always write one with USER_AGENT and a little regex...shouldn't be too hard.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Examples here and here...
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Does anyone have a regex written for the $_SERVER['HTTP_USER_AGENT'] results?

I tried the link, it tells me that 20% of the visitors to my site are 'other'.
programmermatt
Forum Commoner
Posts: 65
Joined: Tue Mar 15, 2005 5:03 pm
Contact:

Post by programmermatt »

Todd_Z wrote: I tried the link, it tells me that 20% of the visitors to my site are 'other'.
A lot of firewalls (Norton comes to mind) can stop certain header information from being sent. This can include browser type and things like 'Previous Page' (which isn't always fun when the website requires it).
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

programmermatt wrote: A lot of firewalls (Norton comes to mind) can stop certain header information from being sent. This can include browser type and things like 'Previous Page' (which isn't always fun when the website requires it).
you could test if this is the case by looking at the raw output of $_SERVER['HTTP_USER_AGENT']

if it is...I'm afraid your stuck, if not continue your regex quest
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Post Reply