Skip to content

Instantly share code, notes, and snippets.

@dmolsen
Created January 30, 2012 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmolsen/1706269 to your computer and use it in GitHub Desktop.
Save dmolsen/1706269 to your computer and use it in GitHub Desktop.
Example of using ua-parser-php
<?php
require("UAParser.php");
$result = UA::parse();
print $result->full;
// -> Chrome 16.0.912/Mac OS X 10.6.8
print $result->browserFull;
// -> "Chrome 16.0.912"
print $result->browser;
// -> "Chrome"
print $result->version;
// -> "16.0.912"
print $result->major;
// -> 16 (minor, build, & revision also available)
print $result->osFull;
// -> "Mac OS X 10.6.8"
print $result->os;
// -> "Mac OS X"
print $result->osVersion;
// -> "10.6.8"
print $result->osMajor;
// -> 10 (osMinor, osBuild, & osRevision also available)
/*
* in select cases the device information will also be captured
*/
print $result->deviceFull;
// -> "Palm Pixi 1.0"
print $result->device;
// -> "Palm Pixi"
print $result->deviceVersion
// -> "1.0"
print $result->deviceMajor;
// -> 1 (deviceMinor also available)
/*
* Some other generic boolean options
*/
print $result->isMobile;
// -> (would return true if the browser met the criteria of a mobile browser based on the user agent information)
print $result->isMobileDevice;
// -> (would return true if the device met the criteria of a mobile device based on the user agent information)
print $result->isTablet;
// -> (would return true if the device was a tablet according to the user agent information)
print $result->isSpider;
// -> (would return true if the device was a spider according to the user agent information)
print $result->isComputer;
// -> (would return true if the device was a computer according to the user agent information)
print $result->isUIWebview;
// -> (would return true if the user agent was from a uiwebview in ios)
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment