Skip to content

Commit

Permalink
Merge pull request #31 from udger/dev
Browse files Browse the repository at this point in the history
Pull v3 parser into master
  • Loading branch information
tiborb authored Jul 16, 2016
2 parents 14e2fb8 + 20c5133 commit f5f0491
Show file tree
Hide file tree
Showing 21 changed files with 761 additions and 1,030 deletions.
111 changes: 98 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,128 @@
# Udger client for PHP
# Udger client for PHP (data ver. 3)
Local parser is very fast and accurate useragent string detection solution. Enables developers to locally install and integrate a highly-scalable product.
We provide the detection of the devices (personal computer, tablet, Smart TV, Game console etc.), operating system and client SW type (browser, e-mail client etc.).
It also provides information about IP addresses (Public proxies, VPN services, Tor exit nodes, Fake crawlers, Web scrapers .. etc.)

- Tested with more the 50.000 unique user agents.
- Up to date data provided by https://udger.com/

### Requirements
- php >= 5.3.0
- ext-sqlite3 (http://php.net/manual/en/book.sqlite3.php)

### Features
- Fast
- Standalone
- Auto updated datafile and cache from remote server with version checking and checksum datafile
- Released under the GNU (LGPL v.3)

### Install

composer install

### Usage
You should review the included examples (`parse.php`, `isbot.php`, `account.php`, `manual_update_data.php` or `full_example.php`)
You should review the included examples (`parse.php`, `account.php`)

Here's a quick example:

```php
require_once __DIR__ . '/vendor/autoload.php';
$parser = new Udger\Parser();
$parser->setDataDir(sys_get_temp_dir() . "/udgercache/");
$parser->setAccessKey('XXXXXX');
$ret = $parser->parse('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36');
require_once dirname(__DIR__) . '/vendor/autoload.php';
$factory = new Udger\ParserFactory();
$parser = $factory->getParser();
$parser->setDataFile(sys_get_temp_dir() . "/udgercache/udgerdb_v3.dat");
$parser->setUA('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36');
$parser->setIP("2A02:598:7000:116:0:0:0:101");
$ret = $parser->parse();
echo "<pre>";
print_r($ret);
echo "</pre>";


Array
(
[user_agent] => Array
(
[ua_string] => Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36
[ua_class] => Browser
[ua_class_code] => browser
[ua] => Chrome 48.0.2564.97
[ua_version] => 48.0.2564.97
[ua_version_major] => 48
[ua_uptodate_current_version] => 48
[ua_family] => Chrome
[ua_family_code] => chrome
[ua_family_homepage] => http://www.google.com/chrome/
[ua_family_vendor] => Google Inc.
[ua_family_vendor_code] => google_inc
[ua_family_vendor_homepage] => https://www.google.com/about/company/
[ua_family_icon] => chrome.png
[ua_family_icon_big] => chrome_big.png
[ua_family_info_url] => https://udger.com/resources/ua-list/browser-detail?browser=Chrome
[ua_engine] => WebKit/Blink
[os] => Windows 7
[os_code] => windows_7
[os_homepage] => https://en.wikipedia.org/wiki/Windows_7
[os_icon] => windows-7.png
[os_icon_big] => windows-7_big.png
[os_info_url] => https://udger.com/resources/ua-list/os-detail?os=Windows 7
[os_family] => Windows
[os_family_code] => windows
[os_family_vendor] => Microsoft Corporation.
[os_family_vendor_code] => microsoft_corporation
[os_family_vendor_homepage] => https://www.microsoft.com/about/
[device_class] => Desktop
[device_class_code] => desktop
[device_class_icon] => desktop.png
[device_class_icon_big] => desktop_big.png
[device_class_info_url] => https://udger.com/resources/ua-list/device-detail?device=Desktop
[crawler_last_seen] =>
[crawler_category] =>
[crawler_category_code] =>
[crawler_respect_robotstxt] =>
)

[ip_address] => Array
(
[ip] => 2A02:598:7000:116:0:0:0:101
[ip_ver] => 6
[ip_classification] => Crawler
[ip_classification_code] => crawler
[ip_hostname] =>
[ip_last_seen] => 2016-02-12 04:28:56
[ip_country] => Czech Republic
[ip_country_code] => CZ
[ip_city] => Prague
[crawler_name] => SeznamBot/3.2-test1
[crawler_ver] => 3.2-test1
[crawler_ver_major] => 3
[crawler_family] => SeznamBot
[crawler_family_code] => seznambot
[crawler_family_homepage] => http://napoveda.seznam.cz/cz/seznambot.html
[crawler_family_vendor] => Seznam.cz, a.s.
[crawler_family_vendor_code] => seznam-cz_as
[crawler_family_vendor_homepage] => http://www.seznam.cz/
[crawler_family_icon] => seznam.png
[crawler_family_info_url] => https://udger.com/resources/ua-list/bot-detail?bot=SeznamBot#id12590
[crawler_last_seen] => 2016-02-15 06:12:28
[crawler_category] => Search engine bot
[crawler_category_code] => search_engine_bot
[crawler_respect_robotstxt] => unknown
[datacenter_name] =>
[datacenter_name_code] =>
[datacenter_homepage] =>
)

)
```

### Running tests


### Running tests
./vendor/bin/codecept run

### Data for parser
- info: https://udger.com/download/data
### Automatic updates download
- for autoupdate data use Udger data updater (https://udger.com/support/documentation/?doc=62)

### Author
The Udger.com Team ([email protected])
- The Udger.com Team ([email protected])

### old v2 format
If you still use the previous format of the db (v2), please see the branch old_format_v2
7 changes: 3 additions & 4 deletions examples/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

require_once dirname(__DIR__) . '/vendor/autoload.php';

$factory = new Udger\ParserFactory();
$factory = new Udger\ParserFactory(sys_get_temp_dir() . "/udgercache/udgerdb_v3.dat");
$parser = $factory->getParser();

// set You Acceskey (see https://udger.com/account/main)
$parser->setAccessKey('XXXXXX');

try {
// set You Acceskey (see https://udger.com/account/main)
$parser->setAccessKey('XXXXXXXX');
$ret = $parser->account();
var_dump($ret);
} catch (Exception $ex) {
Expand Down
38 changes: 0 additions & 38 deletions examples/full_example.php

This file was deleted.

25 changes: 0 additions & 25 deletions examples/isbot.php

This file was deleted.

25 changes: 0 additions & 25 deletions examples/manual_update_data.php

This file was deleted.

22 changes: 6 additions & 16 deletions examples/parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,15 @@
require_once dirname(__DIR__) . '/vendor/autoload.php';

// creates a new UdgerParser object
$factory = new Udger\ParserFactory();
$factory = new Udger\ParserFactory(sys_get_temp_dir() . "/udgercache/udgerdb_v3.dat");
$parser = $factory->getParser();

// set data dir (this php script must right write to cache dir)
$parser->setDataDir(sys_get_temp_dir() . "/udgercache/");

// set You Acceskey (see https://udger.com/account/main)
//$parser->setAccessKey('XXXXXX');
// or download the data manually from http://data.udger.com/[ACCESS_KEY]/udgerdb.dat

//If you want information about fragments
$parser->setParseFragments(true);


try {
$useragent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36';
// Gets information about the current user agent
$ret = $parser->parse($useragent);
$parser->setUA('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36');
$parser->setIP("66.249.64.1");

$ret = $parser->parse();
var_dump($ret);
} catch (Exception $ex) {
echo "Error: " . $ex->getMessage(). PHP_EOL;
}
}
42 changes: 42 additions & 0 deletions src/Helper/IP.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php


namespace Udger\Helper;

/**
* IP address helper
*
* @author tiborb
*/
class IP implements IPInterface{

/**
* Get IP verison
*
* @param string $ip
* @return integer|boolean Returns version or false on invalid address
*/
public function getIpVersion($ip)
{
if (false !== filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
return self::IPv6;
}

if (false !== filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
return self::IPv4;
}
// invalid ip
return false;
}

/**
* Ip to long
*
* @param string $ip
* @return integer
*/
public function getIpLong($ip)
{
return sprintf('%u', ip2long($ip));
}
}
17 changes: 17 additions & 0 deletions src/Helper/IPInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Udger\Helper;

/**
*
* @author tiborb
*/
interface IPInterface {

const IPv4 = 4;
const IPv6 = 6;

public function getIpVersion($ip);

public function getIpLong($ip);
}
Loading

0 comments on commit f5f0491

Please sign in to comment.