Take the 2-minute tour ×

I have a website. When the user clicks on a particular page (say identify.php) I want to find the type of browser the client is using. The browser might be mozilla, IE, opera, chrome or any other mobiles device such as SonyEricssonK610i, SAMSUNG-SGH-E370, SonyEricssonT700 or NokiaN73-1.

Is this possible to detect the user browser?

share|improve this question

10 Answers 10

up vote 4 down vote accepted

You need to look at:


That will contain the User-Agent string for the browser. Beware that almost all browsers claim to be "Mozilla" for compatibility reasons - you need to look for specific text for each browser within that header, eg. "MSIE" for Internet Explorer.

Some examples:

My Firefox calls itself Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv: Gecko/2009060215 Firefox/3.0.11 (.NET CLR 4.0.20506)

My IE7 calls itself Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB6; User-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; http://bsalsa.com) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 4.0.20506)

Note all the trickery in the IE one, eg. claiming to be multiple versions.

share|improve this answer
Note that this information is sent by the client, and can be set to anything (One can put "Hellon World!" in it if he wants) ; So you can try to detect the user-agent, but your application must always work, not depending on this information ! –  Pascal MARTIN Jul 24 '09 at 22:12

Try the php function get_browser();


Or you can try out one of the many lighter weight scripts in the comments of that page.

share|improve this answer
note that you need a recent browscap.ini set up etc. –  Tom Haigh Jul 24 '09 at 21:55

You could look at $_SERVER['HTTP_USER_AGENT']


share|improve this answer

We've started using browsecap and believe it's a more reliable solution that trying to accurately determine browser type by parsing the HTTP_USER_AGENT string ourselves.

edit php.ini file (or .htaccess file) to include:

php_value browscap                        '/path/to/my/browscap/browscap.ini'

... then you're function call in php is:

$browser = get_browser(null, true);
share|improve this answer

For mobiles, use WURFL

if ( $myDevice->is_wireless_device ) {
share|improve this answer


share|improve this answer

This superglobal variable:


is what you need ;-)

share|improve this answer

PHP provides a function called get_browser that checks the user-agent header and tries to guess the browser against a whitelist. It's quite limited, but it works for the most common browsers.

If it doesn't fit your application, then you might need to create a custom function.

share|improve this answer

This variable provides you with the User Agent string of the requesting device. From here, you can use regex to cheThe number of reasons that you shouldn't do this are plentiful:

  1. User Agents are easily spoofed and thus unreliable
  2. User Agent strings are inconsistent, constantly changing (i.e. not future-proof) and not easily interpreted (though here is a list of them)

I suggest doing capability checking with Javascript, as jQuery does.

share|improve this answer

Use the HTTP_USER_AGENT string to detect the browser, like everyone else has mentioned. Here is an example of what it will look like:


Just record the values for various browsers, and then check for keywords like Chrome. Most likely you will want to check for Webkit or other rendering agents because that will affect how the page is displayed.

share|improve this answer

Your Answer


