I am trying to fetch the ip address of my machine through php. For that I am writing the code like:
<?php echo "<br />".$_SERVER['REMOTE_ADDR'];?>
But this piece of code is not working. It is returning "::1
".
Please help me how to get the actual IP Address.
::1
is the actual IP. It is an ipv6 loopback address (i.e. localhost). If you were using ipv4 it would be127.0.0.1
.If you want to get a different IP address, then you'll need to connect to the server through a different network interface.
If you mean getting the user's IP address, you can do something like :
It will get the user's actual IP address, regardless of proxies etc.
If you are trying to run localhost, this answer will fix your problem. Just few changes on
search all "listen" words ex:
Make like this.
than restart your apache
will show
Listen 127.0.0.1
you can see answer in this detailed answer link
Simple answer: You are using it on local server. Try running
in real server. Or you can also user online php executor.
Look at the output of
phpinfo()
. If the address is not on that page, then the address is not available directly through PHP.$_SERVER['REMOTE_ADDR'] is the IP address of the client.
$_SERVER['SERVER_ADDR'] is the IP address of the server.
Reference: http://php.net/manual/en/reserved.variables.server.php