Unknown IP address?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I'm using

         $ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ?

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?

Re: Unknown IP address?

Steven Paul wrote:
Quoted text here. Click to load it

It's probable that your server environment uses another variable  
(HTTP_CLIENT_IP for instance).

Examin the printout of the phpinfo() function to find the correct key.


Re: Unknown IP address?

*** Steven Paul escribió/wrote (Mon, 21 Aug 2006 14:40:34 -0600):
Quoted text here. Click to load it

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(){
        list($ip)=explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
        return $ip;
        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

Site Timeline