Skip to content

Latest commit

 

History

History
71 lines (54 loc) · 2.23 KB

README.md

File metadata and controls

71 lines (54 loc) · 2.23 KB

A Flamework library for decoding User Agent strings

This library is designed to be used with Flamework, but works standalone too.

Usage:

# single shot
$ret = useragent_decode($ua);

# when decoding in batches
$ret = useragent_decode_cached($ua);

# return structure
$ret = array(
  'agent'          => 'chrome',
  'agent_version'  => '15.0.874.121',
  'engine'         => 'webkit',
  'engine_version' => '535.2',
  'os'             => 'osx',
  'os_version'     => '10.7.2',
);

Possible values

agent will be one of the following, with the full version number in agent_version:

  • chrome
  • safari
  • firefox
  • msie
  • dalvik (android VM, not actually the browser)
  • opera
  • netscape
  • konqueror
  • blackberry (pre-safari)

engine contains the rendering engine, with the full version number in engine_version:

  • webkit
  • gecko
  • trident
  • presto

os and os_version contain the platform, with the following values:

  • osx/n.n(.n)
  • iphone/n.n(.n)
  • ipad/n.n(.n)
  • ipod/n.n(.n)
  • windows/xp
  • windows/xp-x64
  • windows/vista
  • windows/7
  • linux/i686
  • linux/x86_64
  • android/n.n(.n)
  • blackberry/$model

When a field does not match one of the known values, it will be set to null.

Caveats

  • Not all browsers, rendering engines and platforms are supported - this is by design! Only common agents are included.
  • We just return "linux/i686" rather than e.g. "Ubuntu", since most Linux flavors don't give distro, plus nobody cares.
  • Chromium returns "chrome" - same thing anyway, plus it has a different version number.
  • We differentiate iPad, iPhone and iPod, even though they are the same OS. You can easily patch this locally if you don't need to know.