At http://php.net/manual/en/reserved.variables.server.php there is an
advice to use
|$_ENV['REMOTE_ADDR']|
from softontherocks at gmail dot com.
In general the value of HTTP_X_FORWARDED_FOR is for case when your
server runs after a reverse proxy (eg. balancer server).
If your server runs behind a reverse proxy, the $_SERVER['REMOTE_ADDR']
is the source address of reverse proxy while
$_SERVER['HTTP_X_FORWARDED_FOR'] contains "forwarded" source address of
the client at the first position of comma separated string value.
Jan.
I have been having some trouble with creating a way to store an IP address of a site visitor for tracking users site visits.
So far I have heard using:
$ip = $_SERVER['REMOTE_ADDR']?:($_SERVER['HTTP_X_FORWARDED_FOR']?:$_SERVER['HTTP_CLIENT_IP']);
Would you consider this the best way?