我无法在 php 中获取我的 IP 地址
我正在尝试编写一个小脚本来打印客户端的IP。我尝试在本地主机上运行它,但无法获取 IP 地址。相反,我得到了类似 ::1 的信息。
这是代码:
<?php echo $_SERVER['REMOTE_ADDR'];?>
为什么这没有按预期工作?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是 IPv6 中的环回地址(IPv4 中为 127.0.0.1)。
这是预期的行为。如果您使用 Firefox,则可以导航至
about:config
,搜索disableIPv6
并将其设置为true
。然后您将看到 127.0.0.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 fordisableIPv6
and set it totrue
. You'll then see 127.0.0.1.So yes, it's working.
它工作正常。那是您的 IP 地址...它的 IPv6 版本。如果您通过 IPv4 连接,它将显示为 127.0.0.1。
这些是环回地址。它们允许您连接到您自己的计算机,而无需使用实际的网络接口。请参阅http://en.wikipedia.org/wiki/Loopback#Virtual_network_interface
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