I hope this is something easy I am overlooking but here goes:
I have a table called: country which has the following fields:
IP_FROM NUMERICAL (DOUBLE) Beginning of IP address range.
IP_TO NUMERICAL (DOUBLE) Ending of IP address range.
COUNTRY_CODE CHAR(2) Two-character country code based on
COUNTRY_NAME VARCHAR(50) Country name based on ISO 31
Here are a few lines from the country table which starts at 33996344 and
ends at :
ip_from ip_to country_code country_name
33996344 33996351 GB UNITED KINGDOM
50331648 83886079 US UNITED STATES
94585424 94585439 SE SWEDEN
<approx 65000 rows >
3714175488 3714175743 DK DENMARK
3715104768 3715629055 JP JAPAN
3717201920 3718840319 KR KOREA, REPUBLIC OF
The IP_FROM and IP_TO fields of the database are numeric representations of
the dotted IP address.
The formula to convert an IP Address of the form A.B.C.D to an IP Number is:
IP Number = A x (256*256*256) + B x (256*256) + C x 256 + D
So here is what I do in PHP:
$resolved=$DB_site->query_first("SELECT * FROM country WHERE '$resolvingip'
BETWEEN ip_from AND ip_to");
$resolvecountry = $resolved[country_code];
so I type in: 22.214.171.124 and $resolvingip shows as: 3574963808
when I check $resolved[ip_from] I find out the SELECT statement looks up
335544320 369098751 US UNITED STATES
instead of looking up this line:
3574956032 3574972415 IT ITALY
which really makes me think the SELECT statement is dropping the last
I tried ip: 10.25.215.30 and $resolvingip shows as 169465630 which looks up
correctly since it is only 9 digits.
When I try ip: 126.96.36.199 $resolvingip shows as 1148033927 but the
SELECT statement drops the last digit and goes to a 9 digit again:
Any help is greatly appreciated..
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php