Tag Archives: geoip

GeoIP PHP extension

12 Feb

Install GeoIP PHP Extension

Install GeoIP C API

Install the PHP extension

  • Install the PHP extension using the PECL repository
    • pecl install geoip
  • Configure php.ini
    • echo “extension=geoip.so” > /etc/php.d/geoip.ini
  • Restart Apache
    • service httpd restart

Install GeoIP Lite Database

  • Downlad the Binary version of the GeoLite City Database from http://www.maxmind.com/app/geolitecity
  • Extract the contents of the distribution
    • gunzip GeoLiteCity.dat.gz
  • Move the dat file to Linux standard shareable location
    • mkdir -p /usr/local/share/GeoIP
    • mv GeoLiteCity.dat /usr/local/share/GeoIP/GeoIPCity.dat

      {info:title=Make Note}

      • In the copy/move step above ensure that you copy to is named GeoIPCity.dat, otherwise the APIs will not find it.

      {info}

       

Test the API

  • In your PHP code embed the following code:
$infos = geoip_db_get_all_info();
if (is_array($infos)) {
    echo '<pre>' . print_r($infos,TRUE) . '</pre>';
}

API reference

References

Advertisements