kieranbarnes Independent PHP, WordPress & CubeCart Programmer

City & Country Location Finding with GeoIP

Posted on January 14, 2008

Following on from a previous post, "PHP Geo-IP Location in 4 lines", I've had a look at stalking people a bit more. Here's how to lookup their location specific to city.

As usual you will need the MaxMind GeoLite City binary database.

Here's the code

country_code . " " . $record->country_code3 . " " . $record->country_name . "";
echo "Region: ".$record->region."";
echo "City: ".$GEOIP_REGION_NAME[$record->country_code][$record->region]." ".$record->city."";
echo "Post Code: ".$record->postal_code."";
echo "Lat: ". $record->latitude."";
echo "Long: ".$record->longitude."";

geoip_close($gi);
?>

You should get results, similar to

Country Code: GB GBR United Kingdom
Region: M6
City: South Gloucestershire Hill
Post Code:
Lat: 51.6514
Long: -2.5156
GB GBR United Kingdom Hill 51.6514 -2.5156

* Remember to keep your MaxMind databases upto date!


Related posts

  1. PHP Geo-IP Location in 4 lines
    Want to look up IP addresses to a geographical location? Firstly, download maxmind_geoip.php and GeoIP...
  2. Auto Updating GeoIP Binary Databases
    Here's how I keep on top of updating the GeoIP binary databases used by various...
  3. PHP Export as CSV
    A client recently requested an option to extract search results from their PHP application as...
  4. Block Countries in Apache
    Assuming you have mod_geoip installed in apache we can block certain countries in 6 lines...
  5. Yahoo GeoLocation API
    The Yahoo Maps API is the best API I've found for using on in internal...

Comments (2) Trackbacks (0)
  1. Thanks for this Kieran my son! I had shyed away from MaxMind – perhaps assuming because they had a paid product their free one would be wizzle – but alas i was wrong.

    That donate a beer button is awesome haha

  2. Does maxmind not have uk postcode info you think?


Leave a comment

(required)

No trackbacks yet.