We use $_SERVER['REMOTE_ADDR'] to find out the client’s IP address in PHP.

But some time it dose not returns the true IP address of the client.
Point to noted that if client is connect to the Internet through Proxy Server then $_SERVER['REMOTE_ADDR'] in PHP just returns the IP address of the Proxy Server not of the client’s machine.

So here is a simple function in PHP to find out the real IP address of the client’s machine. There are extra Server variable which might be available to determine the exact IP address of the client’s machine in PHP, they are HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR.
Simple function to find real IP address in PHP

function get_real_ip_addr()
{
if(!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
else if(!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;
}

The above  function return true IP address of  remote machine using PHP.

For this first of all check IP address of the remote machine, if it is false then it will check IP Address is pass from proxy, if yes then it will return otherwise it will return remote computer IP address.

So enjoy

mrphpguru freelancer

founder and CEO

oneanll