|
Posted by Alvaro G. Vicario on 08/21/06 22:14
*** Steven Paul escribió/wrote (Mon, 21 Aug 2006 14:40:34 -0600):
> $ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ?
> $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
>
> to get a visitor's IP address, but every once in a while I get
> "unknown, unknown" instead of an address. Is there something I'm
> leaving out?
I'm afraid that obtaining client IP address is not rocket science. In
particular, HTTP_X_FORWARDED_FOR is generated by (some/most?) proxies and
it isn't 100% reliable. However, it's your best guess.
BTW, HTTP_X_FORWARDED_FOR can be a comma separated list of address so your
function needs some extending:
function estimated_client_ip(){
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
list($ip)=explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
return $ip;
}else{
return $_SERVER['REMOTE_ADDR'];
}
}
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Navigation:
[Reply to this message]
|