an issue with the ip function variables ?
lima-city → Forum → Sonstiges → English
-
Hi
when i try to use an IP function in my own script using the HTTP_X_FORWARDED_FOR variable, the ip showed by the variable is something like this : 69.147.251.52, 127.0.0.1 ?!
why the HTTP_X_FORWARDED_FOR add the localhost ip 127.0.0.1 near the visitors IP ? is that can be fixed ?
Thank you -
Diskutiere mit und stelle Fragen: Jetzt kostenlos anmelden!
lima-city: Gratis werbefreier Webspace für deine eigene Homepage
-
Create a php file with the following content:
<?PHP echo "<pre>"; print_r($_SERVER); echo "</pre>"; ?>
With this little script, you'll see all useable server variables and their contents. Dunno, what you want to fetch, but HTTP_X_FORWARDED_FOR is not accurate.
If you specify your request a little bit more, we can try to find a solution, if the code above does not return the expected result. -
fabo schrieb:
Create a php file with the following content:
<?PHP echo "<pre>"; print_r($_SERVER); echo "</pre>"; ?>
With this little script, you'll see all useable server variables and their contents. Dunno, what you want to fetch, but HTTP_X_FORWARDED_FOR is not accurate.
If you specify your request a little bit more, we can try to find a solution, if the code above does not return the expected result.
i use this php code to get visitors IP's :
if (getenv(HTTP_X_FORWARDED_FOR))
{
$ip=getenv(HTTP_X_FORWARDED_FOR);
}
elseif(getenv(HTTP_CLIENT_IP)){
$ip=getenv(HTTP_CLIENT_IP);
}else{ $ip=getenv(REMOTE_ADDR);
}
but the IP i get it looks like this : 69.147.251.52, 127.0.0.1 and this is not correct the correct ip is just the first part 69.147.251.52 but the server add the localhost IP which is "127.0.0.1", and the problem is with HTTP_X_FORWARDED_FOR variable and you can see that in phpinfo()
the php file that you told me to create, what name should i give it to it ?
thanks -
Whatever you like ;) You just need to run it and check the output.
But the output of HTTP_X_FORWARDED_FOR is normal. The X-Forwarded for header might contain multiple addresses, comma separated, if the request was forwarded through multiple proxies.
You could split it:
<?php function getIPfromXForwarded() { $ipString = @getenv("HTTP_X_FORWARDED_FOR"); $addr = explode(",", $ipString); return $addr[sizeof($addr) - 1]; } if (@getenv("HTTP_X_FORWARDED_FOR")) { $ip = getIPfromXForwarded(HTTP_X_FORWARDED_FOR); } elseif (getenv("HTTP_CLIENT_IP")) { $ip = getenv("HTTP_CLIENT_IP"); } else { $ip = getenv("REMOTE_ADDR"); } ?>
Beitrag zuletzt geändert: 22.5.2010 8:43:35 von fabo -
Diskutiere mit und stelle Fragen: Jetzt kostenlos anmelden!
lima-city: Gratis werbefreier Webspace für deine eigene Homepage