Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

beranek1/php-user-agent-analyser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UAA: User Agent Analyser

Open-source PHP library for analysing user agents.

Optimised for Gecko (Firefox), AppleWebKit (Chrome, Safari, Edge) and Trident (Internet Explorer) user agents, but also supports most of the others.

Usage

include "uaa.php"
$uaa = analyse_user_agent($_SERVER["HTTP_USER_AGENT"]);
$browser_name = $uaa["browser"]["name"];
$browser_version = $uaa["browser"]["version"];
$os_name = $uaa["os"]["name"];
$os_version = $uaa["os"]["version"];
$device = $uaa["device"]["name"];
$cpu = $uaa["device"]["cpu"];
$is_mobile = $uaa["is_mobile"];
$is_bot = $uaa["is_bot"];

Try it out with test.php.

Features

  • Detects browser name and version
  • Detects operation system (OS) name and version
  • Detects device name/identifier and cpu type if given

Example return values

//Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0
array ( "device" => array ( "cpu" => "x64" ), "os" => array ( "name" => "Windows", "version" => "10.0" ), "browser" => array ( "name" => "Firefox", "version" => "68.0" ), "is_mobile" => 0, "is_bot" => 0);
//Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.2 Safari/605.1.15
array ( "device" => array ( "name" => "Macintosh" ), "os" => array ( "name" => "Mac OS X", "version" => "10_15" ), "browser" => array ( "name" => "Safari", "version" => "605.1.15" ), "is_mobile" => 0, "is_bot" => 0 );