Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reliable way to detect browser , version and plattfom in php

Tags:

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

like image 354
Jeffrey Nicholson Carré Avatar asked Dec 08 '12 17:12

Jeffrey Nicholson Carré


1 Answers

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.

like image 52
Ian Roberts Avatar answered Nov 04 '22 23:11

Ian Roberts