1

I'm developing a PHP application and storing the IP address of the user in a database using $_SERVER['REMOTE_ADDR']

This returns ::1 on a local environment (Apache is set up locally on macOS Sierra).

I understand from previous posts this is because theres is no "round trip" to my ISP. But are there any ways of testing this, i.e. to make sure the code $_SERVER['REMOTE_ADDR'] will return the correct address once the application has been deployed to a live (not local) hosting environment?

The effect I'm after is getting my "real" outbound IP address, as in what would be shown if I visited a site like http://www.whatsmyip.org/

The application I'm building will also show the IP address of the user after it's been stored in a database. So as a second question, if I were to write logic to filter out a local IP from being displayed, should I filter out ::1 and 127.0.0.1, or are there others too?

John
  • 199
  • 9

1 Answers1

0

::1 is your "home" address in IPv6, just like 127.0.0.1 is in IPv4

https://en.wikipedia.org/wiki/IPv6_address

::1/128 — The loopback address is a unicast localhost address. If an application in a host sends packets to this address, the IPv6 stack will loop these packets back on the same virtual interface (corresponding to 127.0.0.1/8 in IPv4).

The problem with getting your "real" outbound address is your local machine might not know what that is. For instance, Amazon Web Services has a control plane that your server actually lives in. So your machine's IP is within that control plane, not the Internet. You can assign it an external IP, but there's no internal way for your machine to find that IP. You actually have to perform other actions(specific to AWS) to get it.

Community
  • 1
  • 1
Machavity
  • 28,730
  • 25
  • 78
  • 91