Tags

, , , ,

To getting the Real IP Address of client in PHP is very simple using following function, even if user is behind a proxy server.

function getRealIpAddressOfClient()
{
  if (!empty($_SERVER['HTTP_CLIENT_IP']))
  {
    $ip_address=$_SERVER['HTTP_CLIENT_IP'];
  }
  else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))  
  //check IP is pass from proxy
  {
    $ip_address=$_SERVER['HTTP_X_FORWARDED_FOR'];
  }
  else
  {
    $ip_address=$_SERVER['REMOTE_ADDR'];
  }
  return $ip_address;
}
Advertisements