Permalink
Browse files

Fix IPv4 lookup issue

  • Loading branch information...
chrislim2888 committed Aug 12, 2015
1 parent 77433e9 commit 1ed55aa02402247d75e3d61d998f6d2af53ee261
Showing with 14 additions and 8 deletions.
  1. +5 −0 ChangeLog
  2. +3 −4 IP2Location.php
  3. BIN databases/IP-COUNTRY.BIN
  4. BIN databases/IP2LOCATION-LITE-DB1.BIN
  5. +6 −4 example.php
View
@@ -1,5 +1,10 @@
Revision History for PHP Module for IP2Location
7.2.3 Wed Aug 12 10:29:37 2015
* Fixes:
- Fix IPv4 lookup issue.
7.2.2 Thu Jul 30 10:27:55 2015
* Fixes:
View
@@ -19,7 +19,7 @@
*
*/
namespace Ip2Location;
namespace IP2Location;
/**
* IP2Location database class
@@ -32,7 +32,7 @@ class Database {
*
* @var string
*/
const VERSION = '7.2.2';
const VERSION = '7.2.3';
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Error field constants ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -975,8 +975,7 @@ private static function ipBetween($version, $ip, $low, $high) {
*/
private static function ipVersionAndNumber($ip) {
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
// Use bin2hex + base_convert to deal with normal PHP ints
return [4, (int) base_convert(bin2hex(inet_pton($ip)), 16, 10)];
return [4, sprintf('%u', ip2long($ip))];
} elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
// Use bcBin2Dec to deal with BCMath ints
return [6, self::bcBin2Dec(inet_pton($ip))];
View
Binary file not shown.
Binary file not shown.
View
@@ -1,25 +1,27 @@
<?php
require_once 'IP2Location.php';
var_dump(class_exists('IP2Location\Database'));
/*
Cache whole database into system memory and share among other scripts & websites
WARNING: Please make sure your system have sufficient RAM to enable this feature
*/
// $db = new \Ip2Location\Database('./databases/IP-COUNTRY-SAMPLE.BIN', \Ip2Location\Database::MEMORY_CACHE);
// $db = new \IP2Location\Database('./databases/IP-COUNTRY-SAMPLE.BIN', \IP2Location\Database::MEMORY_CACHE);
/*
Cache the database into memory to accelerate lookup speed
WARNING: Please make sure your system have sufficient RAM to enable this feature
*/
// $db = new \Ip2Location\Database('./databases/IP-COUNTRY-SAMPLE.BIN', \Ip2Location\Database::MEMORY_CACHE);
// $db = new \IP2Location\Database('./databases/IP-COUNTRY-SAMPLE.BIN', \IP2Location\Database::MEMORY_CACHE);
/*
Default file I/O lookup
*/
$db = new \Ip2Location\Database('./databases/IP-COUNTRY-SAMPLE.BIN', \Ip2Location\Database::FILE_IO);
$db = new \IP2Location\Database('./databases/IP2LOCATION-LITE-DB1.BIN', \IP2Location\Database::FILE_IO);
$records = $db->lookup('8.8.8.8', \Ip2Location\Database::ALL);
$records = $db->lookup('8.8.8.8', \IP2Location\Database::ALL);
echo '<pre>';
echo 'IP Number : ' . $records['ipNumber'] . "\n";

0 comments on commit 1ed55aa

Please sign in to comment.