Should a MAMP return ::1 as IP on localhost? Should a MAMP return ::1 as IP on localhost? sql-server sql-server

Should a MAMP return ::1 as IP on localhost?


Same question, and found a valid solution, tested, works well. I wanted to have the ip addy - of 127.0.0.1 as well instead of having to accept the the ::1 and debate the whole IPv4/6 issues. So, i trolled for a few moments and fell onto a 2008 comment made by @Brad - here:http://board.issociate.de/thread/489575/SERVERquotREMOTEADDRquot-returning-1.html

Summarizing - (on Mac OS - Mountain Lion in particular)

sudo vi /etc/apache2/httpd.conf

Find where your apache is 'listen'-ing to the ips/ports, etc... Typically this will be a line looking like this

Listen 80

Make it look like this:

Listen 127.0.0.1:80

Resave it.Restart Apache.Voila!

Now $_SERVER[REMOTE_ADDR] will look like this 127.0.0.1.

Hope it helps someone.


::1 is the IPv6 equivalent of IPv4 127.0.0.1 address.

You can convert IPv6 address to IPv4 address using function inet_ntop() as Adam, said.

http://php.net/manual/en/function.inet-ntop.php


Modifying the /etc/apache2/httpd.conf or even /private/etc/hosts isn't the solution. It's returning ::1 because it's the IPv6 equivalent to the old (but gold) IPv4's 127.0.0.1. As it's defined in the /privates/etc/hosts, whenever you access http://localhost it assumes IPv6 ::1. So it's the expected behavior.

A workaround would be to access http://127.0.0.1 directly. It'll work just fine. But remember that IPv6 availability is increasing. You could make sure your server (after deployment) will only respond to IPv4 but in the mid term, if your site/web app does not handle both IPv4 and IPv6 properly, there's a great chance something will go wrong within 1/2 years. Or sooner, we never know.