Re: Getting and storing user IP address
| From: | Ian | Date: | Wed, 25 Mar 2015 16:20:55 +0000 |
| Subject: | Re: Getting and storing user IP address | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324707@lists.php.net to get a copy of this message | ||
On 23/03/2015 16:18, michael bredthauer wrote:
> 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?
>
>
Hi,
Take a look at this function by Corey Ballou:
http://blackbe.lt/advanced-method-to-obtain-the-client-ip-in-php/
It checks all the following headers and looks for multiple values from
chained proxies.
HTTP_CLIENT_IP
HTTP_X_FORWARDED_FOR
HTTP_X_FORWARDED
HTTP_X_CLUSTER_CLIENT_IP
HTTP_FORWARDED_FOR
HTTP_FORWARDED
REMOTE_ADDR
Regards
Ian
--