OK I think I get the problem. You have to be careful with the version of the DB you download. I downloaded the full DB - but this is not free and is encoded! You need to download this file: http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/ .
It is a gunzip file, which you need to extract the file GeoIP.dat. If you can't do this, download a free extractor called 7-zip from http://www.7-zip.org/ .
Place the extracted file into a folder called "geoinc". Into that folder also include the file geoip.inc. I renamed the file to geoip.inc.php.
This code now works for me:
<?php
include("{$_SERVER['DOCUMENT_ROOT']}/geoinc/geoip.inc.php");
$gi = geoip_open("{$_SERVER['DOCUMENT_ROOT']}/geoinc/GeoIP.dat",GEOIP_STANDARD);
echo geoip_country_code_by_addr($gi, "24.24.24.24") . "\t" .
geoip_country_name_by_addr($gi, "24.24.24.24") . "\n";
echo geoip_country_code_by_addr($gi, "80.24.24.24") . "\t" .
geoip_country_name_by_addr($gi, "80.24.24.24") . "\n";
geoip_close($gi);
?>
I get the output:
US United States ES Spain
Just do this to get the code and country of an user:
<?php
include("{$_SERVER['DOCUMENT_ROOT']}/geoinc/geoip.inc.php");
$gi = geoip_open("{$_SERVER['DOCUMENT_ROOT']}/geoinc/GeoIP.dat",GEOIP_STANDARD);
echo geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']) . "\t" .
geoip_country_name_by_addr($gi, $_SERVER['REMOTE_ADDR']) . "\n";
geoip_close($gi);
?>
Just be aware, if you're testing this on localhost, the code won't work because the $_SERVER will return "127.0.0.1", which obviously does not have a country.