I cannot get my ip address in php
I am trying to write a small script that prints ip of the client. I am trying to run it on my localhost, but I am not able to get the IP address. Instead I get something like ::1.
Here's the code:
<?php echo $_SERVER['REMOTE_ADDR'];?>
Why this is not wo开发者_如何学Crking as expected?
::1
Is the loopback adress (127.0.0.1 in IPv4) in IPv6.
This is the expected behaviour. If you use Firefox, you can navigate to about:config
, search for disableIPv6
and set it to true
. You'll then see 127.0.0.1.
So yes, it's working.
It is working correctly. That is your IP addresses... the IPv6 version of it. If you had connected over IPv4 it would have shown as 127.0.0.1.
These are loopback addresses. They allow you to connect to your own computer without using an actual network interface. See http://en.wikipedia.org/wiki/Loopback#Virtual_network_interface
精彩评论