Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remote_addr not returning IPv4 address

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.

like image 356
Andrew Kolvik Avatar asked May 30 '10 15:05

Andrew Kolvik


People also ask

How to get IPv4 address in PHP?

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.

What is $_ server [' Remote_addr ']?

$_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']

Can $_ server Remote_addr be spoofed?

Yes, it's safe. It is the source IP of the TCP connection and can't be substituted by changing an HTTP header.

What is _server Remote_addr?

$_SERVER['REMOTE_ADDR'] gives the IP address from which the request was sent to the web server.


1 Answers

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

like image 159
Gumbo Avatar answered Oct 11 '22 12:10

Gumbo