James Bachini

legacy

  • Setting up Maxmind GEOIP2 Legacy Database with PHP or Javascript

    This is the php code I use to access geoip data from Maxmind’s geoip database: <?php $gpath = getcwd() . “/GeoIPCity.dat”; if (isset($_SERVER[‘HTTP_X_FORWARDED_FOR’])) { $myip = $_SERVER[‘HTTP_X_FORWARDED_FOR’]; } if (isset($_SERVER[‘REMOTE_ADDR’])) { $myip = $_SERVER[‘REMOTE_ADDR’]; } include(“./geoipcity.inc”); $gi = geoip_open($gpath,GEOIP_STANDARD); $record = geoip_record_by_addr($gi,$myip); $city = $record->city; $countrycode = $record->country_code; geoip_close($gi); echo ‘countrycode = “‘.$countrycode.’”; city =…