Reply to Re: Unknown IP address?

Your name:

Reply:


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
--

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация