Hello all,
I am trying to update a function of mine to detect for private ip ranges.
Here is what I have so far, and of course, I am stuck at the part where i
need to compare the $ip to the $private_ip array to see if there is a match.
can anyone help out ? i am searching now on preg_replace, i think that is
where i need to start, but not 100% sure.
Thanks.
function getipaddress()
{
$ip;
if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
else if (getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
else if (getenv("HTTP_X_FORWARDED_FOR")) $ip =
getenv("HTTP_X_FORWARDED_FOR");
else $ip = "UNKNOWN";
$private_ip = array("/^0\./", "/^127\.0\.0\.1/", "/^192\.168\..*/",
"/^172\.((1[6-9])|(2[0-9])|(3[0-1]))\..*/", "/^10\..*/", "/^224\..*/",
"/^240\..*/");
//do something here if a match, like die()
return $ip;
}