function getRealIpAddr(){ if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip;}
In this PHP function, first attempt is to get the direct IP address of client’s machine, if not available then try for forwarded for IP address using HTTP_X_FORWARDED_FOR. And if this is also not available, then finally get the IP address using REMOTE_ADDR.
second part could be repeated for each page you need:
if($_SERVER['REMOTE_ADDR']=='999.999.999.999')
{
Redirect the user to
http://my page.com
}
else
{
Load my page
}
This sould be an easy method that should work, but wantabe hackers could cause a problem with “HTTP_” headers. In that they can easily be faked by the client. I could make your function belive I have any address, simply by sending it an X-Forwarded-For header.