ø Don’t waste your time reading this blog ø

MaxMind GeoIP.js blocked on your site? Make your own GeoIP locator service

Filed under: web 2.0 — Tags: — taewoo @ 9:18 pm December 13, 2009

If you send too much traffic to MaxMind’s geo-IP location service, they will cut you off. Ok, maybe they just don’t like you. In fact, they’ll give you this warning/error:

<!DOCTYPE HTML PUBLIC “-//IETF//DTD HTML 2.0//EN”>
<html>

<head><title>302 Found</title></head>

<body>
<h1>Found</h1>
<p>The document has moved <a href=”http://j.maxmind.com:666//app/geoip.js”>here</a>.</p>
<hr>
<address>Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.7a Server at www.maxmind.com Port 80</address>
</body>

</html>

Yes, gay indeed.

If you need their service, you might want to try implementing your own service with their downloadable database. They have several methods of quering the database. If you have linux knowledge, I highly recommend the Linux/Apache method (it’s super fast and super easy to install):

Here are steps, for people who are operating Ubuntu/Debian

1. Download the database as outlined here:

wget -N -q http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoLiteCity.dat.gz

2. Install the mod_ip for apache as outlined here:

apt-get install libapache2-mod-geoip

emacs vi /etc/apache2/mods-available/geoip.conf

(modify geoip.conf to this)

<IfModule mod_geoip.c>
  GeoIPEnable On
  GeoIPDBFile /path/to/your/GeoLiteCity.dat
</IfModule>

/etc/init.d/apache2 restart

Now you can query the IP location from your PHP like so:

<html>
<body>
<?php
$country_code = apache_note(”GEOIP_COUNTRY_CODE”);
$region = apache_note(”GEOIP_REGION”);
$city = apache_note(”GEOIP_CITY”);

echo $city. “, “. $region;
?>
</body>
</html>

Voila!