önce şu kod yardımıyla ip'yi alın;
<?php
if (getenv(HTTP_X_FORWARDED_FOR)) {							
    $ip = getenv(HTTP_X_FORWARDED_FOR); 
} else { 
    $ip = getenv(REMOTE_ADDR);
}
echo $ip; //ip adresini verir
?>
daha sonra bu ip nin hangi ülkeye ait olduğunu bulun şu fonksiyon yardımıyla;
function getCountryCode($ip)
{
include("geoip.inc");
$gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
$countryCode = geoip_country_code_by_addr($gi,$ip);
geoip_close($gi);
return $countryCode;
}
include ile çektiğimiz geoip.inc şurdan indirebilirsiniz
bundan sonra çıkacak $countryCode sizin istemediğiniz ülkenin koduysa hata sayfasına yönlendirebilirsiniz kullanıcınızı..