I’ve searched for this and everything I find is way more than I need. I’ve done this in JavaScript before, but I would really prefer using PHP. How would I go about displaying a message to my visitors, depending on which browser they’re using?
Example:
IE User would see: “You’re using Internet Explorer”
Firefox User would see: “You’re using Mozilla Firefox”
I’m not exactly sure if there are other major browsers besides IE, Firefox, Chrome, Safari, and Opera. But I would at least want to have a message directed to each one of those browsers individually. Thank you.
To identify the user’s browser server-side, you’ll have to parse the
$_SERVER['HTTP_USER_AGENT']variable…… Or, probably better, use the
get_browserfunction — just note you’ll have to configure something in php.ini, or you’ll get this kind of warning :Like the PHP manual page says :
After downloading that file and adding this line to php.ini :
The following portion of code :
Gives me :
on firefox 3.5 ; and :
On a recent version (4.0.203.2) of google chrome for Linux — well, considering it’s some kind of nightly build, I suppose it’s normal that it’s not recognized…
As a reference, here is it’s user-agent string :
This show that get_
browser isnice ; but maybe not perfect for some cutting-edge test browser — still, should work fine with most “common” browsers, I suppose…