$_Server["Remote_Addr"] Gives Server Ip Rather Than Visitor Ip

$_SERVER['REMOTE_ADDR'] gives the IP Address of the server instead of the IP Address of the user

This means your server is probably behind some sort of reverse proxy, like a load balancer or CDN. Your PHP server is not receiving direct connections from clients, those connections go through some intermediate before, so the IP of that intermediate is all your server sees.

In this situation the intermediate proxy typically forwards the actual client's IP in some specified HTTP header to your PHP server. That is when you very explicitly and very selectively use something like $_SERVER['HTTP_X_FORWARDED']; if and only if and when you know that you're in this kind of situation and which HTTP header you can trust. Consult the documentation of your host/proxy/network situation and it'll tell you what header to use.

Php $_SERVER['REMOTE_ADDR'] gives different ip everytime

The IP on your local machine is a private IP assigned by your router. A remote server gets the public IP of the WAN interface of the router. If the IP is changing, your ISP must be assigning your IP dynamically each time you connect.

Another possibility is that your ISP relays your web traffic through proxy servers. Then $_SERVER['REMOTE_ADDR'] is the IP of the proxy. If the IP changes each time, they have multiple proxies that they load balance.

$ _SERVER ['REMOTE_ADDR'] return IP of server, not visitor IP

you may use this function

function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}

$ipaddr = getRealIpAddr();

Why does $_SERVER['REMOTE_ADDR'] return the gateway ip rather than the remote ip with a fortigate router?

The Fortigate has an option to "enable NAT" on a policy, which doesn't mean translate the addresses (it does that for you anyway), but does mean it alters some packets replacing the remote IP with the gateway IP.

Make sure that "Enable NAT" is disabled, and $_SERVER['REMOTE_ADDR'] will work as expected.

Why is $_SERVER['REMOTE_ADDR'] showing a wrong ip?

I don't care if they are behind a proxy, VPN, etc;

You have to, if they are using a VPN, or a proxy, or NAT then $_SERVER['REMOTE_ADDR'] will contain that ip and not of the user, and that is what you're getting.

UPDATE: I've talked to the specific user in question and he said he is NOT using Google Translate. Why else would a Google IP show in REMOTE_ADDR?

That Google IP you have mentioned in your OP belongs to google-proxy-64-233-173-164.google.com which is the proxy that this visitor's computer or ISP is using

If you were to check HTTP_X_FORWARDED_FOR or HTTP_CLIENT_IP You would get that information



Related Topics



Leave a reply



Submit