Question

I have been looking for a reliable way to have (at least the less obscure ones) :

  1. the name of the browser
  2. the version
  3. and the platform (OS) it is on
  4. maybe more information but the 3 info above are enough.

I want to display a custom content according to these information, example :

If the user wants to know how to clear the cookies on his browser. Let's say i have many contents already available for many browser. versions And i want to load the appropriate content automatically

Is there a way not involving Javascript to get these values?

I have use cases where the browser is not found or inaccurate. So i would like to have the most reliable solution.

Here are 2 websites that does exactly what i need :

  1. www.whatismybrowser.com (contacted the owner to know how to do it in PHP)
  2. HawkBrowser Really exhaustive test , not free

Other link with partial solutions:

  1. upgrademybrowser.org using the old browsercap of Aug 2012 (source)
  2. Google's www.whatbrowser.org

Spent many days trying, seaching, but to no success. I found many hints from Stackoverflow community:

  1. browsercap with get_browser(). the project was discontinued (for now 8 Aug. 2012) and doesn't detect some modern popular handheld device.
  2. Javascript detect feature approach : Modernirz. Not good approach for what i want to do, to long and will have to be updated often.
  3. jQuery.browser Not good enough not enough possibility.
  4. quirksmode.org javascript and not accurate with mobile for now and would prefer PHP version.

Other useful links :

  1. Stakoverflow Answer 1
  2. Stackoverflow Answer 2
  3. PHP mobile Detect
  4. PIWIK analytic reports

EDIT 1 So far i have tested the answers and comments. These solutions are very satisfying:

  • PHP mobile detect the last version is really good, if you are using this it would be good to give the client the form in the example so they can contribute to the project. (thanks to @Pekka)
  • WURFL less recent but very good also. (thanks to @Ian Roberts)

    EDIT 2 PHP mobile detect uses WURFL

UPDATE

Make sure that the header you receive are not modified by any other library.

For example some security libraries like OWASP PhpSec [ABANDONED] change the header structure into a custom object and PHP mobile detect doesn't have access to all the information it needs anymore

For those of you using OWASP PhpSec [ABANDONED] the http library is modifying the global header object structure. (December 2013) So if you have issues just use PHP mobile detect before you include any OWASP PhpSec class using the http library

Was it helpful?

Solution

Have you considered WURFL? Its main aim is to classify mobile device browsers but it claims to have a mode that identifies desktop ones too.

OTHER TIPS

The Browser info in PHP you get from get_browser()

so you can use A ajax call to the PHP site, provides information about the user agent

e.g.

PHP

$info = get_browser(null, true);
echo json_encode($info);

The Array provided by get_browser looks like

Array
(
    [browser_name_regex] => ^mozilla/5\.0 (windows; .; windows nt 5\.1; .*rv:.*) gecko/.* firefox/0\.9.*$
    [browser_name_pattern] => Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9*
    [parent] => Firefox 0.9
    [platform] => WinXP
    [browser] => Firefox
    [version] => 0.9
    [majorver] => 0
    [minorver] => 9
    [cssversion] => 2
    [frames] => 1
    [iframes] => 1
    [tables] => 1
    [cookies] => 1
    [backgroundsounds] =>
    [vbscript] =>
    [javascript] => 1
    [javaapplets] => 1
    [activexcontrols] =>
    [cdf] =>
    [aol] =>
    [beta] => 1
    [win16] =>
    [crawler] =>
    [stripper] =>
    [wap] =>
    [netclr] =>
)

This of course isn't a reliable solution because you can change your browser string as you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top