This goes through whatever's thrown at you in the order most likely to get the real IP of the user
function get_user_ip()
{
$ipRoutes = array
(
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'HTTP_VIA',
'HTTP_X_COMING_FROM',
'HTTP_COMING_FROM',
'REMOTE_ADDR',
);
foreach ($ipRoutes as $route)
{ if (!empty($_SERVER[$route]))
{
$is_ip = ereg('^([0-9]{1,3}.){3,3}[0-9]{1,3}', $_SERVER[$route], $regs);
if ($is_ip && (count($regs) > 0))
return $regs[0];
}
}
return '0.0.0.0';
}