jump to navigation

Browser Detection With a PHP Script – Browser.php December 29, 2011

Posted by Tournas Dimitrios in PHP.

If the need for browser detection is more than just analyzing whether it is IE , Firefox , Chrome or Safari , then Browser.php is definitely a must-bookmark . This PHP class  helps us collecting data about a visitor’s browser including : platform used – browser – browser version . It can detect almost every popular browser including mobile + tablet devices and robots with a few PHP lines of code .

Excerpt from the Browser.php Website :

Detecting the user’s browser type and version is helpful in web applications that harness some of the newer bleeding edge concepts. With the browser type and version you can notify users about challenges they may experience and suggest they upgrade before using such application. Not a great idea on a large scale public site; but on a private application this type of check can be helpful .

In an active project of mine we have a pretty graphically intensive and visually appealing user interface which leverages a lot of transparent PNG files. Because we all know how great IE6 supports PNG files it was necessary for us to tell our users the lack of power their browser has in a kind way.

Searching for a way to do this at the PHP layer and not at the client layer was more of a challenge than I would have guessed; the only script available was written by Gary White and Gary no longer maintains this script because of reliability. I do agree 100% with Gary about the readability; however, there are realistic reasons to desire the user’s browser and browser version and if your visitor is not echoing a false user agent we can take an educated guess .

A simple practical example could be :

$browser = new Browser();
if( $browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 3 ) {
echo 'You have FireFox version 3 or greater';

Of course the PHP-class should be downloaded into the same directory as the detection script or into PHP’s include path directory .

Note : If you are interested for client-side browser detection with Javascript then visit this website .



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s