This package provides information about the user's GEO, its browser, OS and client type (desktop or mobile). The library works with free GeoLite2 databases.
We recommend installing this package with Composer.
To download Composer, run in the root directory of your project:
curl -sS https://getcomposer.org/installer | phpYou should now have the file composer.phar in your project directory.
Run in your project root:
php composer.phar require kipkaev55/client-checker:1.1.*
You should now have the files composer.json and composer.lock as well as
the directory vendor in your project directory. If you use a version control
system, composer.json should be added to it.
After installing the dependencies, you need to require the Composer autoloader from your code:
require 'vendor/autoload.php';Straightforward:
require_once __DIR__ . '/vendor/autoload.php'; // Autoload files using Composer autoload
use ClientChecker\Client;
$client = new Client(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 YaBrowser/17.3.1.838 Yowser/2.5 Safari/537.36',
'172.68.11.66',
array( // on version 1.0.0 use './GeoLite2-City.mmdb' instead array()
'dbip' => array( //
'type' => 'mysql', //
'host' => '127.0.0.1', //
'db' => 'dbip', //
'user' => 'root', //
'password' => '123456' //
), //
'sypex' => './SxGeoCity.dat', //
// 'geoip' => './GeoLite2-City.mmdb', //
'sorting' => array('sypex', 'dbip', 'geoip') //
) //
);
/*
or
$client = new Client(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 YaBrowser/17.3.1.838 Yowser/2.5 Safari/537.36',
'172.68.11.66',
'./GeoLite2-City.mmdb',
'ru'
); //russian locale (supports [en, de, es, fr, ja, pt-BR, ru, zh-CN])
or
$client = new Client(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 YaBrowser/17.3.1.838 Yowser/2.5 Safari/537.36',
'172.68.11.66',
'./GeoLite2-City.mmdb',
'ru',
'path/to/custom/regexes.php'
); //custom regexes and russian locale
*/
echo ($client->isMobile()) ? 'true' : 'false'; //false
echo "\n";
echo $client->getOs(); //Mac OS X 10.12.4
echo "\n";
echo $client->getBrowser(); //Yandex Browser 17.3.1
echo "\n";
$geo = $client->getIpData();
echo $geo['country']; //RU
echo "\n";
echo $geo['city']; //Moscow
echo "\n";- This software is Copyright (c) 2017 by Pro.Motion.
- This is free software, licensed under the MIT license
- Ua-parser PHP Library is licensed under the MIT license
- The user agents data from the ua-parser project is licensed under the Apache license
- The initial list of generic feature phones & smartphones came from Mobile Web OSP under the MIT license
- The initial list of spiders was taken from Yiibu's profile project under the MIT license.
- GeoIP2 PHP API licensed under the Apache License, Version 2.0.