RE: [PHP] HTTP_X_FORWARDED_FOR?
| From: | Jon Haworth | Date: | Thu, 10 Jan 2002 17:14:02 +0000 |
| Subject: | RE: [PHP] HTTP_X_FORWARDED_FOR? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-80052@lists.php.net to get a copy of this message | ||
> Okay, thanks. 'Cause I mean, the REMOTE_ADDR is still there. So you
> mean that the HTTP_X_FORWARDED_FOR isn't working while I'm working
localhost?
REMOTE_ADDR contains the IP of the computer that requested your page.
If it was a proxy doing the request, you'll have the proxy's IP in this
variable, and the IP of the computer that requested the page from the proxy
will be in HTTP_X_FORWARDED_FOR.
This means the best way to grab an IP is with a a function like this:
<?php
function getIP () {
if (getenv(HTTP_X_FORWARDED_FOR)) {
$ip = getenv(HTTP_X_FORWARDED_FOR);
} else {
$ip = getenv(REMOTE_ADDR);
}
return $ip;
}
?>
I'm unsure what happens with multiple proxies, and I'd be interested to know
- do you get an array of HTTP_X_FORWARDED_FORs? Do you just get the first or
the last?
Cheers
Jon