
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.
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");
%>
|  |
|