Re: Getting and storing user IP address
| From: | Jan Vávra | Date: | Wed, 25 Mar 2015 10:47:24 +0000 |
| Subject: | Re: Getting and storing user IP address | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324706@lists.php.net to get a copy of this message | ||
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?