Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mallat committed Jan 4, 2017
2 parents f5f0491 + 835e2ea commit c9f8001
Show file tree
Hide file tree
Showing 5 changed files with 376 additions and 187 deletions.
81 changes: 46 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ It also provides information about IP addresses (Public proxies, VPN services, T

### Features
- Fast
- LRU cache
- Released under the GNU (LGPL v.3)

### Install
Expand All @@ -27,8 +28,10 @@ Here's a quick example:
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->setDataFile(sys_get_temp_dir() . "/udgercache/udgerdb_v3.dat");
//$parser->setCacheEnable(false);
//$parser->setCacheSize(4000);
$parser->setUA('Mozilla/5.0 (Linux; Android 5.1.1; SAMSUNG SM-A510F Build/LMY47X) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/3.5 Chrome/38.0.2125.102 Mobile Safari/537.36');
$parser->setIP("2A02:598:7000:116:0:0:0:101");
$ret = $parser->parse();
echo "<pre>";
Expand All @@ -38,41 +41,46 @@ echo "</pre>";

Array
(
[user_agent] => 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_string] => Mozilla/5.0 (Linux; Android 5.1.1; SAMSUNG SM-A510F Build/LMY47X) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/3.5 Chrome/38.0.2125.102 Mobile Safari/537.36
[ua_class] => Mobile browser
[ua_class_code] => mobile_browser
[ua] => Mobile Samsung Browser 3.5
[ua_version] => 3.5
[ua_version_major] => 3
[ua_uptodate_current_version] =>
[ua_family] => Mobile Samsung Browser
[ua_family_code] => mobile_samsung_browser
[ua_family_homepage] => http://developer.samsung.com/internet
[ua_family_vendor] => SAMSUNG
[ua_family_vendor_code] => samsung
[ua_family_vendor_homepage] => http://www.samsung.com/
[ua_family_icon] => samsung_browser.png
[ua_family_icon_big] => samsung_browser_big.png
[ua_family_info_url] => https://udger.com/resources/ua-list/browser-detail?browser=Mobile Samsung Browser
[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
[os] => Android 5.1 lollipop
[os_code] => android_5_1
[os_homepage] => https://en.wikipedia.org/wiki/Android_Lollipop
[os_icon] => android.png
[os_icon_big] => android_big.png
[os_info_url] => https://udger.com/resources/ua-list/os-detail?os=Android 5.1 lollipop
[os_family] => Android
[os_family_code] => android
[os_family_vendor] => Google, Inc.
[os_family_vendor_code] => google_inc
[os_family_vendor_homepage] => https://www.google.com/about/company/
[device_class] => Smartphone
[device_class_code] => smartphone
[device_class_icon] => phone.png
[device_class_icon_big] => phone_big.png
[device_class_info_url] => https://udger.com/resources/ua-list/device-detail?device=Smartphone
[device_marketname] => Galaxy A5 (2016)
[device_vendor] => Samsung
[device_vendor_code] => samsung
[device_vendor_homepage] => http://www.samsung.com/
[device_vendor_icon] => samsung.png
[crawler_last_seen] =>
[crawler_category] =>
[crawler_category_code] =>
Expand Down Expand Up @@ -121,6 +129,9 @@ Array
### Automatic updates download
- for autoupdate data use Udger data updater (https://udger.com/support/documentation/?doc=62)

### Documentation for programmers
- https://udger.com/pub/documentation/parser/PHP/html/

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

Expand Down
2 changes: 2 additions & 0 deletions examples/parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// creates a new UdgerParser object
$factory = new Udger\ParserFactory(sys_get_temp_dir() . "/udgercache/udgerdb_v3.dat");
$parser = $factory->getParser();
//$parser->setCacheEnable(false);
//$parser->setCacheSize(4000);

try {
$parser->setUA('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36');
Expand Down
24 changes: 23 additions & 1 deletion src/Helper/IP.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getIpVersion($ip)
return self::IPv6;
}

if (false !== filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
else if (false !== filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
return self::IPv4;
}
// invalid ip
Expand All @@ -39,4 +39,26 @@ public function getIpLong($ip)
{
return sprintf('%u', ip2long($ip));
}


/**
* Ipv6 to array
*
* @param string $ip
* @return array
*/
public function getIp6array($ip){
// expand - example: "2600:3c00::" -> "2600:3c00:0000:0000:0000:0000:0000:0000"
$hex = unpack("H*hex", inet_pton($ip));
$ipStr = substr(preg_replace("/([A-f0-9]{4})/", "$1:", $hex['hex']), 0, -1);

$ipIntArray = array();
$ipStrArray = split(":", $ipStr);

foreach ($ipStrArray as &$value) {
$ipIntArray[] = hexdec($value);
}

return $ipIntArray;
}
}
2 changes: 2 additions & 0 deletions src/Helper/IPInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ interface IPInterface {
public function getIpVersion($ip);

public function getIpLong($ip);

public function getIp6array($ip);
}
Loading

0 comments on commit c9f8001

Please sign in to comment.