简体   繁体   中英

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 working 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM