Forum Moderators: coopster
Hi did try the instructions on the page below, but they didn't work!
<snip>
Any help much appreciated.
Dexie.
[edited by: eelixduppy at 2:44 pm (utc) on July 13, 2007]
[edit reason] no URI's please - see charter [/edit]
function userIP(){
switch ($_SERVER){
case 'HTTP_CLIENT_IP':
$userip = $_SERVER['HTTP_CLIENT_IP'];
break;
case 'HTTP_X_FORWARDED_FOR':
$userip = $_SERVER['HTTP_X_FORWARDED_FOR'];
break;
case 'HTTP_X_FORWARDED':
$userip = $_SERVER['HTTP_X_FORWARDED'];
break;
case 'HTTP_FORWARDED_FOR':
$userip = $_SERVER['HTTP_FORWARDED_FOR'];
break;
case 'HTTP_FORWARDED':
$userip = $_SERVER['HTTP_FORWARDED'];
break;
default:
$userip = $_SERVER['REMOTE_ADDR'];
break;
}
return $userip;
}
There would be a lot of SEO issues with blocking ip's that dont come from the countries that you want. So IP address blocking may well be a bit drastic for what you want, but thats why im not posting this in an SEO forum :)
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
$IPaddress=$_SERVER['HTTP_X_FORWARDED_FOR'];}else{
$IPaddress=$_SERVER['REMOTE_ADDR'];}
$two_letter_country_code=iptocountry($IPaddress);
function iptocountry($ip){
$numbers = preg_split( "/\./", $ip);
include("ips/".$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){
$two_letter_country_code=$ranges[$key][1];break;}}}
if($two_letter_country_code==""){
$two_letter_country_code="unknown";}
return $two_letter_country_code;}
if($two_letter_country_code=="RU"){die();} the url ('ips/') needs to point at a database of country IPs which you have to download from here -- phptutorial.info/iptocountry/the_script.html.
you can set it up to disallow any country you want. or it would be simple enough to amend the script so it just allows countries (instead of disallowing)
and it is flat file too, so you don't even need a database.