remote_addr not returning IPv4 address

2019-02-06 16:04发布

I am using xampp on localhost and when I use $_SERVER["REMOTE_ADDR"] it returns ::1 (also does this in phpinfo()). Why does it do this? I want it to return a normal ip address like 127.0.0.1. My operating system is windows vista.

4条回答
仙女界的扛把子
2楼-- · 2019-02-06 16:25

Your apache is listening for IPv6 connections by default (::1 being local loopback). If you really just want IPv4, try to disable disable IPv6 connections in your apache configuration:

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:

Listen 0.0.0.0:80
Listen 192.170.2.1:80
查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-02-06 16:32

::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. So ::1 is the same as 127.0.0.1 only via IPv6 instead of IPv4.

查看更多
三岁会撩人
4楼-- · 2019-02-06 16:39

You have to disable IPv6 support in your OS for apache to stop showing these IPv6 format addresses, when you want the IPv4 format. I disabled IPv6 support and its working as expected now.

The following instructions to disable IPv6 could be helpful, 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.

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

查看更多
唯我独甜
5楼-- · 2019-02-06 16:45

Go to XAMPP control panel. Open Apache(httpd.conf) which can be found in the first row i.e. Apache Module's 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. Restart Apache and you will no longer see ::1 in your browser. This will happily return your localhost i.e. 127.0.0.1

查看更多
登录 后发表回答