When you are connected to internet from the internet connection, it is not always directly connected to internet gateway. It may be connected to host computer which will be controlling most of the clients computers and so on. In this architecture of network, visitors IP address is not the actual IP address from which he/she is connected to internet. In such cases, your PHP script using $_SERVER['REMOTE_ADDR'] will give you wrong IP address. You need to cross check the IP address from share connection, forwarded IP, proxy etc to filter out the real IP address from the visitors machine. You can solve this issue by using the following php function.
This function will give you the real IP address of the visitors visiting your site, so later you can track it or save it in your records, table etc.
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;
}




