PHP $_SERVER['REMOTE_HOST'] returns ::1 [duplicate]
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 $_S开发者_如何学CERVER['REMOTE_HOST'] to return something like 127.0.0.1, but it's returning ::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.
use $_SERVER['REMOTE_ADDR']
It will give the IP address
Refer this link for more info about $_SERVER
The variable you're looking for is:
<?php echo $_SERVER['REMOTE_ADDR']; ?>
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.
精彩评论