简体   繁体   English

remote_addr没有返回IPv4地址

[英]remote_addr not returning IPv4 address

I am using xampp on localhost and when I use $_SERVER["REMOTE_ADDR"] it returns ::1 (also does this in phpinfo() ). 我在localhost上使用xampp,当我使用$_SERVER["REMOTE_ADDR"]它返回::1 (也在phpinfo()执行此操作)。 Why does it do this? 为什么这样做? I want it to return a normal ip address like 127.0.0.1. 我希望它返回像127.0.0.1这样的普通IP地址。 My operating system is windows vista. 我的操作系统是windows vista。

::1 is an IPv6 address and an abbreviation for 0:0:0:0:0:0:0:1 that is the loopback address to the local machine. ::1IPv6地址 ,是0:0:0:0:0:0:0:1的缩写,它是本地计算机的环回地址 So ::1 is the same as 127.0.0.1 only via IPv6 instead of IPv4. 所以::1仅通过IPv6而不是IPv4与127.0.0.1相同。

Your apache is listening for IPv6 connections by default ( ::1 being local loopback ). 您的apache默认侦听IPv6连接( ::1本地环回 )。 If you really just want IPv4, try to disable disable IPv6 connections in your apache configuration: 如果您真的只想要IPv4,请尝试在apache配置中禁用禁用IPv6连接:

If you want Apache to handle IPv4 connections only, regardless of what your platform and APR will support, specify an IPv4 address on all Listen directives, as in the following examples: 如果您希望Apache仅处理IPv4连接,无论您的平台和APR支持什么,请在所有Listen指令上指定IPv4地址,如以下示例所示:

Listen 0.0.0.0:80
Listen 192.170.2.1:80

Go to XAMPP control panel. 转到XAMPP控制面板。 Open Apache(httpd.conf) which can be found in the first row ie Apache Module's Actions. 打开Apache(httpd.conf),可以在第一行找到,即Apache Module的Actions。 Go to listen (you can Ctrl + F this) which shows 80 (if you have ipv6 active) change it to Listen 0.0.0.0:80 and you are done. 去听(你可以按Ctrl + F这个)显示80(如果你有ipv6激活)将它改为Listen 0.0.0.0:80然后你就完成了。 Restart Apache and you will no longer see ::1 in your browser. 重新启动Apache,您将不再在浏览器中看到::1 This will happily return your localhost ie 127.0.0.1 这将很高兴返回您的localhost即127.0.0.1

You have to disable IPv6 support in your OS for apache to stop showing these IPv6 format addresses, when you want the IPv4 format. 您需要在操作系统中禁用IPv6支持,以便在需要IPv4格式时停止显示这些IPv6格式地址。 I disabled IPv6 support and its working as expected now. 我禁用了IPv6支持,它现在按预期工作。

The following instructions to disable IPv6 could be helpful, http://support.microsoft.com/kb/929852 以下有关禁用IPv6的说明可能会有所帮助, http://support.microsoft.com/kb/929852

Just so you know i followed the steps described in the above link and i'm using Windows 7 not Vista though i doubt there could be any or many differences. 只是你知道我按照上面链接中描述的步骤,我使用Windows 7而不是Vista虽然我怀疑可能有任何或许多差异。

I recently ran into this issue, though i don't ever remember enabling ipv6 support on my system, could be done by Microsoft in one of their updates (maybe). 我最近遇到过这个问题,虽然我不记得在我的系统上启用ipv6支持,可以由微软在其中一个更新中完成(也许)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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