GeoIP, Apache and PHP

This is a short notice about how to use GeoIP with Apache and PHP. MaxMind’s GeoIP is a database of ip addresses ordered by the corresponding countries. This can be used to guess a user’s prefered language for a multilanguale website.

  • apt-get install libapache2-mod-geoip
  • get the latest database version
  • Apache configuration:
    GeoIPEnable On
    GeoIPDBFile /path/to/GeoIP.dat
echo apache_note("GEOIP_COUNTRY_CODE") . " - " . apache_note("GEOIP_COUNTRY_NAME");

The free to use database is updated every month, so it’s good to set up a cronjob.

Get more information here:

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Time limit is exhausted. Please reload the CAPTCHA.