PHP $_SERVER['REMOTE_HOST'] returns ::1 [duplicate]

微笑、不失礼 提交于 2020-01-03 19:00:55

问题


Possible Duplicate:
should $ip=$_SERVER['REMOTE_ADDR']; return ::1 on a mamp localhost?

I am trying to get the IP address of the website visitor in PHP. I'm expecting $_SERVER['REMOTE_HOST'] to return something like 127.0.0.1, but it's returning ::1.


回答1:


::1 is the IPv6 equivalent of 127.0.0.1 - see http://www.juniper.net/techpubs/software/erx/erx50x/swconfig-routing-vol1/html/ipv6-config5.html The long form of that is
0:0:0:0:0:0:0:1 - but the :: stands in for the run of 0's.




回答2:


use $_SERVER['REMOTE_ADDR']

It will give the IP address

Refer this link for more info about $_SERVER




回答3:


The variable you're looking for is:

<?php echo $_SERVER['REMOTE_ADDR']; ?>



回答4:


There are two possibilities here:

  1. the address is ipv6. this has already been pointed out so i think this isn't the case
  2. there is a firewall running on the server. as you say this is your local web server, check for any firewalls on it as some firewalls do block the server information.

Let know how it goes.



来源:https://stackoverflow.com/questions/2482033/php-serverremote-host-returns-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!