views:

96

answers:

1

Need to retrieve a users IP, and my localhost is returning '::1' as the IP, and I am curious as to if this is expected behaviour

Running MAMP on Snow Leopard.

+6  A: 

::1 is the IPv6 equivalent of IPv4 127.0.0.1 address.

You can convert IPv6 address to IPv4 address using function inet_ntop() as Adam, said.

http://php.net/manual/en/function.inet-ntop.php

Tomasz Kowalczyk
I believe you can convert between IPv4 and IPv6 using `inet_ntop`
adam
@adam, yes, you are right. @Mild: if you are satisfied with my answer, please accept ;]
Tomasz Kowalczyk
$ip=inet_ntop($_SERVER['REMOTE_ADDR']); is returning Warning: inet_ntop() [function.inet-ntop]: Invalid in_addr value in /Applications/MAMP/htdocs/createstudios/wp-content/themes/createstudios/page.php on line 18
Mild Fuzz
Was your PHP library built with IPv6 support?
Tomasz Kowalczyk
Not sure, how would I check?
Mild Fuzz
and, ultimately, does it matter? Are these values good enough?
Mild Fuzz
I don;t know if unprepared IPv6 string can be input for inet_ntop(). There is some preparing going down in manual - see comments, maybe they will enlighten you a bit.
Tomasz Kowalczyk