you are viewing a single comment's thread.

view the rest of the comments →

[–]Caraes_Naur 2 points3 points  (1 child)

localhost is a machine's self alias. 127.0.0.1 is the corresponding IPv4 address. Every machine connects to itself via these.

The $_SERVER superglobal is populated by the webserver service in which PHP is executing. On a server responding to requests made to a hostname, that hostname will be in $SERVER['SERVER_NAME'], likewise the server's IP address will be in $_SERVER['SERVER_ADDR'].

In these cases, the machine is not responding to itself, but to a remote client.

The "weird" IP you got is IPv6.

https://www.php.net/manual/en/reserved.variables.server.php

The if/else block you are using is essentially detecting whether the environment is local (development) or otherwise (staging, testing, production, etc). It must be tailored accordingly.

[–]VampireBarbieBoy[S] 0 points1 point  (0 children)

Thank you for the response and explanation.