I'm getting Notice: Undefined index: HTTP_X_FORWARDED_FOR in the Function below:
function _ip( )
{
return ( preg_match( "/^([d]{1,3}).([d]{1,3}).([d]{1,3}).([d]{1,3})$/", $_SERVER['HTTP_X_FORWARDED_FOR'] ) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'] );
}
You should be using the getenv() method instead of $_SERVER.
function _ip( )
{
if (preg_match( "/^([d]{1,3}).([d]{1,3}).([d]{1,3}).([d]{1,3})$/", getenv('HTTP_X_FORWARDED_FOR'))
{
return getenv('HTTP_X_FORWARDED_FOR');
}
return getenv('REMOTE_ADDR');
}
Also, I would stick with just $ip = getenv('REMOTE_ADDR')
as spammers can set the HTTP_X_FORWARDED_FOR
header themselves to anything they want while they can't change the remote_addr. The problem is that "good" proxies tell the truth about HTTP_X_FORWARDED_FOR
so you would miss that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With