UAService is a small CodeIgniter custom library that provides browser/user agent, IP, proxy and host detection, and geographical location services (your average browser sniffer with some extra functionality to sniff out IP addresses). It is designed to integrate seamlessly with the PHP CodeIgniter framework. UAService can also be used as a standalone library, without CodeIgniter (CI). However the IP Geolocation functions won't work because they rely on CI's database layer.

0.6.1 2014-05-07 02:36 UTC


Total Downloads Latest Stable Version Build Status

UAService is a small library that provides browser/user agent, IP, proxy and host detection (your average browser sniffer with some extra functionality to sniff out IP addresses).

The library is based on the CodeIgniter library available here: http://vvvlad.com/resources/uaservice

The Composer version of the library excludes the Geolocation component. The functionality was implemented originally relying on the CodeIgniter database layer and the IPInfoDB geolocation database.


Install UAService via composer, edit the composer.json and add:

"require": {
    "php": ">=5.3.0",
    "vvvlad/uaservice": "dev-master"

Then update the project dependencies via:

terminal$ composer update


Autoload the composer dependencies:


Initialize the UAService class:

$ua = new \UAService\UAService();

By default, the user agent and IP address of the current request is parsed and detected on class initialization, the detected properties are exposed as:


To parse a custom User Agent string. The result is an array containing the properties listed above under the 'ua' and 'is' prefixes:

$result = $ua->getUserAgent('User Agent String');

To detect the current request source IP address. The method factors in proxies and excludes private IP ranges, if proxies are present. It thus should return the first routable IP address in the request path.

$result = $ua->getIpAddress();

To detect the IP address proxies that the request was routed thorugh, use the method below. The result is an array of IP addresses for all the proxies in the request header. The array does not imply a specific order of hops the request went through, although the proxies should be appended to the header in the order that the request traverses the proxies.

$result = $ua->getIpProxies();

To detect the hostname of the source of the request use the following:

$result = $ua->getHostName();

Detection Rules

The bottom of the source file class contains the detection rules used. The library is designed to detect most major operating system, device and browser platforms. The rules are processed in order and the first matched rule prevails. This is caused by the fact that user agent strings contain fallback segments. So we want to match the most specific rules first, leave generic webkit and IE rules to last. This unfortunately also means that generic Safari/Webkit and Internet Explorer browsers take more tries to match.