Page 1 of 1

IP Address: Capture and Format

Posted: Wed Sep 06, 2006 9:29 am
by tmaiden
I was wondering if anyone could tell me how to capture a person's ip address who visits my site.

I've seen $_SERVER['REMOTE_ADDR'] and was wondering if this was the best way of doing so.

Also, lets say the user's ip address is: 203.279.16.123 OR 203.279.16.55
How can I have it displayed as 203.279.16.xxx OR 203.279.16.xx

Thanks.

Posted: Wed Sep 06, 2006 2:33 pm
by Mordred
If the user comes through a non-anonymising proxy, that field will have the ip of the proxy. The real ip will be supplied in a http header ($_SERVER['HTTP_something']), for example HTTP_VIA, HTTP_X_FORWARDED_FOR, HTTP_FORWARDED_FOR etc.

About display - explode() the ip dotted quad into an array, change the last item to 'xx', and then join() it again

Posted: Wed Sep 06, 2006 2:40 pm
by feyd
We've had many many threads involving IP addresses, specifically REMOTE_ADDR.. take a look at them.

Quick and cheap for changing the display is explode() as Mordred said.