This example below will tell you the country name and country code based on IP Address.
First, you need to download the latest GeoLite Country Binary Forma from Maxmind, the database is FREE and should be updated monthly.
After that, you also need to download Pure PHP module (geoip.inc) from Maxmind.
Below is the source code:
[php] <?phpinclude("geoip.inc");
$gi = geoip_open(dirname(__FILE__) . "/GeoIP.dat",GEOIP_STANDARD);
$your_ip = $_SERVER[‘REMOTE_ADDR’];
echo "Your IP Address: " . $your_ip . "<br>You come from <b>" . geoip_country_code_by_addr($gi, $your_ip) . "</b> – <b>" . geoip_country_name_by_addr($gi, $your_ip) . "</b><br>";
echo geoip_country_code_by_addr($gi, "24.24.24.24") . "<br>" . geoip_country_name_by_addr($gi, "24.24.24.24") . "<br>"; //US United States
echo geoip_country_code_by_addr($gi, "80.24.24.24") . "<br>" . geoip_country_name_by_addr($gi, "80.24.24.24") . "<br>"; //ES Spain
geoip_close($gi);
?>
[/php]+ Download this example
+ View Demo