php mysql REMOTE_ADDR not working

Joined
12 Feb 2006
Posts
17,674
Location
Surrey
i'm trying to store the visitors ip address in a mysql table but it's not coming out correclt some reason. this is roughyl what i have...

$ip = $_SERVER['REMOTE_ADDR'];

ip is a varchar in the table.

what i end up with everytime is ::1

am i doing something wrong? my error404 checking emails me the ip address of the user and that is correct so unsure what's making this incorrect.
 
Well if it's hosted you'll have to ask your hosts I should imagine.

Otherwise it will be your apache or IIS config.

There should be a class already written for IPv4 - IPv6 conversion which is what you'll need I should imagine.
 
It looks to me like the script is working fine.

::1 is localhost - it's the IPv6 equivalent of 127.0.0.1. If you're running the script on the same machine which is hosting it, and that system is using IPv6 addressing, the visitor IP will come out as ::1. So the script is doing what it's supposed to do. When it's hosted, your visitors will have normal IPv4 addresses which will also be stored correctly.
 
Back
Top Bottom