问题
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:
- the address is ipv6. this has already been pointed out so i think this isn't the case
- 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