Helping ordinary people create extraordinary websites!

Effective Geotargeting with PHP

By Akash Mehta
2008-01-27

Getting started

The database is the key to all our GeoIP work — the better the database, the more accurate the country check. The free database from MaxMind offers “Over 98%” accuracy, which is pretty good, but a 2% failure rate can be a little high for businesses. We'll stick to the free version for the moment; you can grab a copy here — you'll need the “latest GeoLite Country Binary Format” version. You'll also need to get their PHP library here. Finally, download and install the PEAR package, Net_GeoIP — you can do this via command line or grab the package file here. Access to a PHP webserver is assumed. Of course, there's no need to try out these samples; the code is pretty light-weight so you can follow along without testing it out.

Incidentally, if you want to write your own lookup system, a CSV version of the actual IP database is available that is very easy to work with when imported into a SQL database. Bear in mind, however, that the database is very large, and another lookup to a database table for every single user can cause significant server load.





Tutorial pages:
 4 Votes

You might also want to check these out:


Leave a Comment on "Effective Geotargeting with PHP"
You must be logged in to post a comment.

Link to This Tutorial Page!


GET OUR NEWSLETTERS