Codice PHP:
function GetCountry($ip) {
// open ip-to-country file, set correct address...
if ( $file = fopen("ip-to-country.csv","r") ) {
// if successfully opened, read each line of the file
while ( $line = fgetcsv($file,1024,",") ) {
// if our the ip corresponds, return the country name
// $line[2] = country code 2 char,
// $line[3] = country code 3 char, if needed...
if ( ip2long($ip) > $line[0] && ip2long($ip) < $line[1] ) {
return $line[4];
}
}
}
// if this ip has something wrong :?
return false;
}
$country = GetCountry($_SERVER['REMOTE_ADDR']);
echo "Your country is ".$country;
poi scaricati questo file
http://ip-to-country.webhosting.info...ountry.csv.zip