Function takes in IP and returns country's code (abbreviated) There is a separate function and download you can get Which has the list of country codes and country names. Goto: PHPtricks.com/PHPskills.com to download it
PHP Code:
<?php
/*
Function takes in IP and returns country's code (abbreviated)
There is a separate function and download you can get
Which has the list of country codes and country names
Goto: PHPtricks.com/PHPskills.com to download it
*/
function check_country($ip) {
$numbers = preg_split( "/\./", $ip);
include("my_ip_list/".$numbers[0].".php");
$code=($numbers[0] * 16777216) + ($numbers[1] * 65536) + ($numbers[2] * 256) + ($numbers[3]);
foreach($ranges as $key => $value){
if($key<=$code){
if($ranges[$key][0]>=$code){$country=$ranges[$key][1];break;}
}
}
if ($country==""){$country="unkown";}
return $country;
}
//Sample implementation
$user_country = check_country($_SERVER['REMOTE_ADDR']);
echo "You are from: $user_country";
?>