views:

85

answers:

4

Hey all,
    I'm in need of a way to detect mobile browsers server-side. I've heard of various ways to do this, but i'd like a way that requires me to do little to set up and little to maintain, yet still provide me with accurate detection of (at the VERY least) android, iphone/ipod, and blackberry browsers, along with alternatives like opera. So, in short, i'd like to have at least the majority of the mobile market covered, and I'd really prefer virtually all of the market if it doesn't take much.

Any suggestions?

Thanks,
-Trey

+1  A: 

Its just a matter of reading the headers ( http://stackoverflow.com/questions/541430/how-do-i-read-any-request-header-in-php ) and parsing / interpreting this to read the "user-agent", you may be able to find an existing PHP script or maybe just plain regex that will help in figuring out which user-agents are mobile and which are regular pc's / laptops.

There are a lot of different headers, as it indicates the operating system, so as many different mobile OS'es as there are there would be user-agent headers so the script needs to have a list of all valid ones.

Rick
Hey, thanks for the reply, but I was really more looking for a library to avoid this sort of tedious work...
TreyK
@Rick: You can just check the variable `$_SERVER['HTTP_USER_AGENT']`
webbiedave
+2  A: 

WURLF is the ultimate way for mobile browser detection and a PHP API is available.

kgiannakakis
+1, let me just add that it gets updated frequently with new devices and device capabilities
Fanis
This looks pretty good, I think I'll try it out. Thanks!
TreyK
+3  A: 

All you need is get_browser() and a recent browscap.ini that maps the user-agent string to a browser/version and its capabilities.

You can get a usually very up-to-date browscap.ini version from http://browsers.garykeith.com/downloads.asp

VolkerK
A: 

How about http://code.google.com/p/hdapi/ ? Server side mobile detection in PHP.

Richard