|Attention: Cet article/tutorial est ‰gé de plus de 45 jours. Ainsi les informations qu’il contient peuvent être, maintenant, dépassé. Merci de lire toutes les informations qu’il contient pour vous assurez que cet article fonctionnera bien sur votre système|
|Mac OS X 10.3.4 is required will all relevant updates installed
Developers’ Tools are, as always, required for this tutorial
A version of Apache 1.3.x with APXS enabled is also necessary. (several PHPmac tutorials available)
Apache 2 version of mod_geoip is available, however, the method of installing this is outside the scope of this tutorial.
Step 1: Installing MaxMind GeoIP APIThe first step of this tutorial is a fairly straight foward build of the GeoIP API. The source is available free under the GPL
(% Represents the command line prompt)
|% curl -O http://www.maxmind.com/download/geoip/api/c/GeoIP-1.3.4.tar.gz
% gnutar -xzf GeoIP-1.3.4.tar.gz
% cd GeoIP-1.3.4
% make check
% sudo make install
Step 2: Installing mod_geoip for ApacheDownloading and untarring are the first steps
|% curl -O http://www.maxmind.com/download/geoip/api/mod_geoip/mod_geoip_1.2.4.tar.gz
% gnutar -xzf mod_geoip_1.2.4.tar.gz
% cd mod_geoip_1.2.4
Building the actual module is once again fairly simple. This step requires that you have built Apache previously with APXS support
|sudo apxs -cia -I/usr/local/include -L/usr/local/lib -lGeoIP mod_geoip.c|
Once this has completed you need to add the following lines to the end of your Apache httpd.conf file.
# If GeoIP is turned on, turn it on
The paths to the conf file is usually /etc/httpd/httpd.conf. Explaining how to change your httpd.conf file is not within the scope of this tutorial.
|sudo apachectl restart|
Step 3: Using in your PHP web applicationsProbably the easiest part of the entire process is using this in everyday use. Basically, the module provides the country information, all the hard work is done by the module itself. To access the country information in PHP you can use the following script.
$country_code = apache_note(“GEOIP_COUNTRY_CODE”);
$country_name = apache_note(“GEOIP_COUNTRY_NAME”);
That’s it – all done. You can now call on this in all your PHP scripts. This is very effective method of automatically selecting Download Mirrors, providing location specific content, etc. for your visitors.
A word of warning: this method of determining geographical location can sometimes yield incorrect results. For example, if a multinational company has recently expanded to a new country and has taken IP addresses with it. This happened to me and I kept getting British mirrors on some websites when I wanted Irish ones. The moral of the story is to use this to make an initial “guess” – but always provide your users with a way to manually switch countries.
I have also written a little script that plots the location that GeoIP gives to a map of the world. It also checks the IP against the RIPE IP whois, or ARIN for US IPs. You can download the source here Requires GD and GeoIP (obviously)!
If you have any problems don’t hesitate to contact the support team. Click Here. A login is required.