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.
The simplest way to collect the visitor IP address in PHP is the REMOTE_ADDR. Pass the 'REMOTE_ADDR' in PHP $_SERVER variable. It will return the IP address of the visitor who is currently viewing the webpage.
$_SERVER['REMOTE_ADDR'] Returns the IP address from where the user is viewing the current page. $_SERVER['REMOTE_HOST'] Returns the Host name from where the user is viewing the current page. $_SERVER['REMOTE_PORT']
Yes, it's safe. It is the source IP of the TCP connection and can't be substituted by changing an HTTP header.
$_SERVER['REMOTE_ADDR'] gives the IP address from which the request was sent to the web server.
::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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With