Skip to content

Instantly share code, notes, and snippets.

@mbmccormick
Created October 15, 2010 01:38
Show Gist options
  • Save mbmccormick/627449 to your computer and use it in GitHub Desktop.
Save mbmccormick/627449 to your computer and use it in GitHub Desktop.
Query the GeoLiteCity database with user's IP address and return city, state, zip code.
<?php
include("lib/geoipcity.inc");
include("lib/geoipregionvars.php");
$ip = $_SERVER["REMOTE_ADDR"];
$geo = geoip_open("/home/mattps/dontforgetyourumbrella.com/lib/GeoLiteCity.dat", GEOIP_STANDARD);
$record = geoip_record_by_addr($geo, $ip);
$city = $record->city;
$state = $record->region;
$zipcode = $record->postal_code;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment