Forum Moderators: coopster
if(getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
} elseif (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
} elseif (getenv('HTTP_X_FORWARDED')) {
$ip = getenv('HTTP_X_FORWARDED');
} elseif (getenv('HTTP_FORWARDED_FOR')) {
$ip = getenv('HTTP_FORWARDED_FOR');
} elseif (getenv('HTTP_FORWARDED')) {
$ip = getenv('HTTP_FORWARDED');
} else {
$ip = $_SERVER['REMOTE_ADDR']'
}
The HTTP_X_FORWARDED_FOR information is a cortesy of a remote proxy, so you shouldn't rely on it and add some code to fall back to the remote_addr if the HTTP_X_FORWARDED_FOR makes no sense.
This information can easily be faked by users by adding it to a HTTP request themselves.
Note that the X-Forwarded-for header might contain multiple addresses (comma separated), if the request was forwarded through multiple proxies.
Kind regards,
R.
I usualy get Blank ips when Spammers from Nigeria and other Small Afirican countries try to do some Spamming on my site..
Nigerian really sucks.. they keep doing their work very dedicatedly and no matter how many ips you block.. they will keep coming with new one. On an avarage i block more than 100 accounts daily on my site..
see how big pain is this..
Anybody has any other idea about getting blank ips?
Regards
Tabish
if (isset($_SERVER['SERVER_ADDR']) && $_SERVER['SERVER_ADDR'] <> '') {
$_SESSION['ip'] = $_SERVER['SERVER_ADDR'];
} else {
$_SESSION['ip'] = gethostbyname($_SERVER['SERVER_NAME']);
} If the SERVER_ADDR is there, then that's used. If not the IP is looked up through DNS and then stored as a session variable so it only has to be looked up once per session.
So far, I haven't come across a situation where it hasn't worked :)
[edited by: Nutter at 2:13 pm (utc) on Jan. 9, 2007]
The IP address is also required for a double-reverse-lookup, where an IP address is sent to DNS to look up the hostname, and then the hostname is sent back to DNS to look up the IP address. If the IP address looked up from the hostname does not match the original IP address, then the double-reverse lookup fails. As such, it is good for looking up faked REMOTE_HOSTnames, HTTP_REFERERs, or any other IP addresses or hostnames.
The original problem in this thread is that HTTP_X_FORWARDED_FOR will only be sent by 'good' proxies --that is, non-anonymous proxies-- to inform you of the real remote user's IP address. If it's not present, it could simply be that the user is not behind a proxy, so that header won't be sent.
So, the suggestion to fall back to REMOTE_ADDR and to check some of the other possible proxy-appended headers if HTTP_X_FORWARDED_FOR is missing is a good one.
Jim
[edited by: jdMorgan at 7:31 pm (utc) on Jan. 9, 2007]