I needed a quick way to detect what browser any given user visiting my site was using. I used this information to serve them a custom CSS stylesheet. And sure, PHP claims to have a built-in method to achieve this functionality: get_browser. But I ran into problems with that dude: it's slow, it returns way more info than I need (an array of data the tells me everything the browser is capable of), and, the nail in the coffin, it didn't work on my web server (I get a "browscap ini directive not set" error).
Instead of dealing with these issues (which, I believe, would mean calling GoDaddy, who runs my server), I built my own little custom method. I'll show it off after the break.Here's the script.
I'm simply using PHP's Switch feature, which seems to work pretty well. Feel free to borrow and improve it.
Disclaimer: I'm not a PHP expert. I'm sure someone (everyone?) will come along and say this is wildly incorrect, but, hey, it works for me and it is reasonably efficient (thanks to the breaks). In other words, I'm not claiming it's perfect, I'm saying it works for me and I thought I'd share.3/26/2009