MaxMind
Support My Account FAQ My Order
Support My Account FAQ My Order

Apache Module
C
C# Class
Java Class
MS COM Object
Pascal
Perl Module
PHP Module
Python Class
Ruby Module
VB.Net
Support Center


GeoIP PHP API

There are three methods of querying the GeoIP databases from PHP. The easiest to setup is the Pure PHP API. The setup for the high performance PHP extension and mod_geoip APIs is more advanced.

Pure PHP module
Download pure PHP module. Free GeoLite Country and GeoLite City databases are available.

A port to PHP5 of the PHP API is available from PEAR.

The Pure PHP API is cross-platform, works on Windows as well as Linux, and does not require Apache, nor does it require the C API.

PHP Extension on PECL
Download a PHP extension that allows you to embed the GeoIP C Library inside PHP for improved performance. There is a new fork with a more complete implementation.

Using mod_geoip with PHP
For improved performance, you can access the mod_geoip from PHP. There is a trade-off between performance and ease of installation - the Apache module is faster (benchmark), but the pure PHP module is much easier to install.

The following must be installed to use mod_geoip from PHP.

Usage
Once mod_geoip is installed, it is easy to use from PHP. Use something like the following:
<%
$country_code = apache_note("GEOIP_COUNTRY_CODE");
$country_name = apache_note("GEOIP_COUNTRY_NAME");
%>


MaxMind, GeoIP, minFraud and related marks are registered trademarks of MaxMind, Inc.
Copyright© 2012 MaxMind, Inc. All Rights Reserved. Terms of use.