$_SERVER['REMOTE_ADDR'] returns 127.0.0.1.
is that because I installed varnish cache and data goes to varnish, then apache, and server think request came from varnish not client?
$_SERVER['REMOTE_ADDR'] returns 127.0.0.1.
is that because I installed varnish cache and data goes to varnish, then apache, and server think request came from varnish not client?
Get the remote ip address like this:
public function getRemoteIPAddress() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
return $_SERVER['HTTP_CLIENT_IP'];
} else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
return $_SERVER['REMOTE_ADDR'];
}
Beware, $_SERVER['HTTP_X_FORWARDED_FOR'] can contain multiple ips, see How do I get the correct IP from HTTP_X_FORWARDED_FOR if it contains multiple IP Addresses?