Sabrin
asked on
help implement code
hello,
this is what im using to block ips from china and korea on my site
<?
include("/usr/local/etc/ge oip.inc");
$gi = geoip_open("/usr/local/etc /GeoIP.dat ",GEOIP_ST ANDARD);
$IP_Addr = $HTTP_SERVER_VARS["REMOTE_ ADDR"];
if (geoip_country_code_by_add r($gi, $IP_Addr) == CN){
print "no access allowed";
}else if (geoip_country_code_by_add r($gi, $IP_Addr) == KR){
print "no access allowed";
}
geoip_close($gi);
?>
I need help implementing this code! is so if they are using a us proxy they can get in!
if ($_SERVER["HTTP_X_FORWARDE D_FOR"]) {
if ($_SERVER["HTTP_CLIENT_IP" ]) {
$proxy = $_SERVER["HTTP_CLIENT_IP"] ;
} else {
$proxy = $_SERVER["REMOTE_ADDR"];
}
$ip = $_SERVER["HTTP_X_FORWARDED _FOR"];
} else {
if ($_SERVER["HTTP_CLIENT_IP" ]) {
$ip = $_SERVER["HTTP_CLIENT_IP"] ;
} else {
$ip = $_SERVER["REMOTE_ADDR"];
}
}
this is what im using to block ips from china and korea on my site
<?
include("/usr/local/etc/ge
$gi = geoip_open("/usr/local/etc
$IP_Addr = $HTTP_SERVER_VARS["REMOTE_
if (geoip_country_code_by_add
print "no access allowed";
}else if (geoip_country_code_by_add
print "no access allowed";
}
geoip_close($gi);
?>
I need help implementing this code! is so if they are using a us proxy they can get in!
if ($_SERVER["HTTP_X_FORWARDE
if ($_SERVER["HTTP_CLIENT_IP"
$proxy = $_SERVER["HTTP_CLIENT_IP"]
} else {
$proxy = $_SERVER["REMOTE_ADDR"];
}
$ip = $_SERVER["HTTP_X_FORWARDED
} else {
if ($_SERVER["HTTP_CLIENT_IP"
$ip = $_SERVER["HTTP_CLIENT_IP"]
} else {
$ip = $_SERVER["REMOTE_ADDR"];
}
}
Another thing, you should change this line:
$HTTP_SERVER_VARS["REMOTE_ ADDR"];
into
$_SERVER["REMOTE_ADDR"];
$HTTP_SERVER_VARS["REMOTE_ ADDR"]; is depreciated and should not be used anymore (if you ever upgrade PHP it will save you some headaches :)
$HTTP_SERVER_VARS["REMOTE_
into
$_SERVER["REMOTE_ADDR"];
$HTTP_SERVER_VARS["REMOTE_
ASKER
thanks guys, this is my php-4.3.9-3.18
$HTTP_SERVER_VARS will work in PHP4, but not anymore in PHP5 (per default). So, it's not necessary to browse through the code right away to change it, but if you ever come accross line of code with $HTTP_SERVER_VARS, you should make it a habbit to change it.
ASKER
so If someone from china is using ip 1.2.3.4
and connects to a proxy from usa 4.5.6.7
and goes to the site, he will be blocked?
this is what I want!
and connects to a proxy from usa 4.5.6.7
and goes to the site, he will be blocked?
this is what I want!
ASKER
I dont want to block proxy traffic maybe theres a guy from canada
using a proxy in the US i dont want to block him
using a proxy in the US i dont want to block him
ASKER
something like if user is using proxy check real ip
if its from china dont let him in
if user is not using proxy and ip is from china
dont let him in
if its from china dont let him in
if user is not using proxy and ip is from china
dont let him in
ASKER
the geo ip will make sure the ip is from x country and do what I tell!
> so if they are using a us proxy they can get in!
Sorry, I thought that anyone using a proxy was allowed in :)
I'll have a quick bite and then change the code.
Sorry, I thought that anyone using a proxy was allowed in :)
I'll have a quick bite and then change the code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sweet thanks a lot man!
You're welcome :)
<?
include("/usr/local/etc/ge
$access = false;
if ($_SERVER["HTTP_X_FORWARDE
if ($_SERVER["HTTP_CLIENT_IP"
$proxy = $_SERVER["HTTP_CLIENT_IP"]
} else {
$proxy = $_SERVER["REMOTE_ADDR"];
}
$ip = $_SERVER["HTTP_X_FORWARDED
// proxy, so access allowed
$access = true;
} else {
if ($_SERVER["HTTP_CLIENT_IP"
$ip = $_SERVER["HTTP_CLIENT_IP"]
} else {
$ip = $_SERVER["REMOTE_ADDR"];
}
}
// access still false, so geoip test needed
if ($access === false) {
$gi = geoip_open("/usr/local/etc
$IP_Addr = $HTTP_SERVER_VARS["REMOTE_
if (geoip_country_code_by_add
print "no access allowed";
}else if (geoip_country_code_by_add
print "no access allowed";
}
geoip_close($gi);
// proxy, access allowed
} else {
print "access allowed";
}
?>