Forum Moderators: coopster

Message Too Old, No Replies

REMOTE ADDR always showing the same (and wrong) IP addrress

         

guarriman

5:05 pm on Jan 11, 2008 (gmt 0)

10+ Year Member



Hi.

Using PHP v4, I want to get the IP address of each visitor with
$_SERVER["REMOTE_ADDR"]. But it always show the same IP address

What could I be doing wrong?

PS: I've just changed my server configuration, from IPv6 to IPv4 following these steps:
[fedorasolved.org...]

Thank you very much.

[edited by: coopster at 9:56 pm (utc) on Jan. 11, 2008]
[edit reason] removed ip address [/edit]

lammert

6:22 pm on Jan 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The IP address you mention is probably a proxy server or firewall of the company you work or the ISP you are connected through. If you are behinf a firewall or proxy server with NAT translation, your webserver only sees requests with the IP address of that machine. The IP's of connecting computers are on-the-fly replaced by the proxy and the firewall to their own IP address to prevent your internal IP to be known outside of the network. This often has as consequence that you don't see incomming external IP's from withing the network either.

venelin13

1:05 pm on Jan 12, 2008 (gmt 0)

10+ Year Member



In order to retreive the user ip address, you should not relay on the REMOTE_ADDR, only! Here is what I am using:


function getIpAddress() {

$ip = "";

if($_SERVER) {
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}elseif(isset($_SERVER['HTTP_CLIENT_IP'])){
$ip = $_SERVER['HTTP_CLIENT_IP'];
}else{
$ip = $_SERVER['REMOTE_ADDR'];
}
} else {
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');
}
}

return $ip;
}