Skip to content

Commit 1ed55aa

Browse files
committed
Fix IPv4 lookup issue
1 parent 77433e9 commit 1ed55aa

5 files changed

Lines changed: 14 additions & 8 deletions

File tree

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Revision History for PHP Module for IP2Location
22

3+
7.2.3 Wed Aug 12 10:29:37 2015
4+
* Fixes:
5+
6+
- Fix IPv4 lookup issue.
7+
38
7.2.2 Thu Jul 30 10:27:55 2015
49
* Fixes:
510

IP2Location.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
*/
2121

22-
namespace Ip2Location;
22+
namespace IP2Location;
2323

2424
/**
2525
* IP2Location database class
@@ -32,7 +32,7 @@ class Database {
3232
*
3333
* @var string
3434
*/
35-
const VERSION = '7.2.2';
35+
const VERSION = '7.2.3';
3636

3737
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3838
// Error field constants ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -975,8 +975,7 @@ private static function ipBetween($version, $ip, $low, $high) {
975975
*/
976976
private static function ipVersionAndNumber($ip) {
977977
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
978-
// Use bin2hex + base_convert to deal with normal PHP ints
979-
return [4, (int) base_convert(bin2hex(inet_pton($ip)), 16, 10)];
978+
return [4, sprintf('%u', ip2long($ip))];
980979
} elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
981980
// Use bcBin2Dec to deal with BCMath ints
982981
return [6, self::bcBin2Dec(inet_pton($ip))];

databases/IP-COUNTRY.BIN

-2.43 MB
Binary file not shown.

databases/IP2LOCATION-LITE-DB1.BIN

1.02 MB
Binary file not shown.

example.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
<?php
22
require_once 'IP2Location.php';
3+
var_dump(class_exists('IP2Location\Database'));
4+
35

46
/*
57
Cache whole database into system memory and share among other scripts & websites
68
WARNING: Please make sure your system have sufficient RAM to enable this feature
79
*/
8-
// $db = new \Ip2Location\Database('./databases/IP-COUNTRY-SAMPLE.BIN', \Ip2Location\Database::MEMORY_CACHE);
10+
// $db = new \IP2Location\Database('./databases/IP-COUNTRY-SAMPLE.BIN', \IP2Location\Database::MEMORY_CACHE);
911

1012
/*
1113
Cache the database into memory to accelerate lookup speed
1214
WARNING: Please make sure your system have sufficient RAM to enable this feature
1315
*/
14-
// $db = new \Ip2Location\Database('./databases/IP-COUNTRY-SAMPLE.BIN', \Ip2Location\Database::MEMORY_CACHE);
16+
// $db = new \IP2Location\Database('./databases/IP-COUNTRY-SAMPLE.BIN', \IP2Location\Database::MEMORY_CACHE);
1517

1618

1719
/*
1820
Default file I/O lookup
1921
*/
20-
$db = new \Ip2Location\Database('./databases/IP-COUNTRY-SAMPLE.BIN', \Ip2Location\Database::FILE_IO);
22+
$db = new \IP2Location\Database('./databases/IP2LOCATION-LITE-DB1.BIN', \IP2Location\Database::FILE_IO);
2123

22-
$records = $db->lookup('8.8.8.8', \Ip2Location\Database::ALL);
24+
$records = $db->lookup('8.8.8.8', \IP2Location\Database::ALL);
2325

2426
echo '<pre>';
2527
echo 'IP Number : ' . $records['ipNumber'] . "\n";

0 commit comments

Comments
 (0)