我无法在 php 中获取我的 IP 地址

发布于 2024-10-09 08:00:39 字数 177 浏览 0 评论 0原文

我正在尝试编写一个小脚本来打印客户端的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清风无影 2024-10-16 08:00:39
::1

是 IPv6 中的环回地址(IPv4 中为 127.0.0.1)。

这是预期的行为。如果您使用 Firefox,则可以导航至 about:config,搜索 disableIPv6 并将其设置为 true。然后您将看到 127.0.0.1。

所以是的,它正在发挥作用。

::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.

尬尬 2024-10-16 08:00:39

它工作正常。那是您的 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文