You need to use isset checks. Your server will guarantee nothing when it comes to the population of the $_SERVER superglobal, so you need to assume that nothing exists.
PHP Code:
if (isset($_SERVER['HTTP_CLIENT_IP']))
{
$ip_address = $_SERVER['HTTP_CLIENT_IP'];
}
else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else if ($_SERVER['REMOTE_ADDR'])
{
$ip_address = $_SERVER['REMOTE_ADDR'];
}
Should do it.
Although it makes no guarantee, I've never seen the REMOTE_ADDR not set in a webserver environment before.