I have downloaded the csv geoip lite from http://www.maxmind.com/app/geolitecountry. I imported that data into my db as the following tables:
Blocks: startIP, endIP, locid. Location: locid, country, region, city, postalcode, lat, long, met, areacode.
the code that creates the IPnum is:
<? $ip =$_SERVER['REMOTE_ADDR'];
list($w, $x, $y, $z) = explode('.', $ip);
$one = 16777216* $w;
$two = 65536* $x ;
$three = 256*$y;
$ipnum = $one + $two+ $three + $z;
?>
then my query is:
SELECT postalcode FROM location WHERE locid =(SELECT locid FROM blocks WHERE startIP <= '$ipnum' AND endIP>= '$ipnum' LIMIT 1)
for a IP of 69.63.184.142, the ipnum is equal to 1161803918. the db does return a query, however, the location is from Australia, and that ip is definitely not in Australia.
those who are familiar with geoip, is it something I am doing wrong as far as formula goes?
Here's one that I use. If it doesn't get a GET var it uses the user's remote address.