Browser, Tablet and Mobile Device Detection in PHP

Browser, Tablet and Mobile Device Detection in PHP

Many websites present different webpages, versions, navigation and styles depending the type of device.

We often run into this issue and have found a couple of tools to address it.

  • Browscap –http://browscap.org/ – A feature built into PHP which compares the USER AGENT string against a HUGE (50MB+) ini file with regular expression matching.  The matching is comprehensive and very specific,  however the library of User Agents requires frequent updates in this world of every changing devices.   Each lookup can take several seconds,  and a high volume PHP site will likely need to come up with some sort of caching to handle the load caused by this tool.
  • Mobile Dectect – http://mobiledetect.net/ – A lightweight PHP Class which returns quickly.  While it has worked in many reguards,   the smaller size of the listing of User Agents leave me lacking in confidence that it will match all of the devices out there.

This sounds like an opportunity for me to build a comparison tool.   I will call it: browser-detect-compare and it will have the following features

  • When a user visits the page, their user agent is logged
  • Each of the tools in the comparison is queried to return the results
  • The site displays whether the results match between the tools for:
    • Is Mobile
    • Is Tablet
    • Browser Name
    • OS Name
    • OS Version
    • Browser Version
  • If the results do not match,  the user will be allowed to select which results are correct.
  • The site will then display statistics about how correct each of the tools are for each of the tracked metrics.

Please leave comments  of other features that will be use ful here.