The following code to find the actual local IP address (e.g. 192.168.1.X) of the host server works fine on the dev machine
$ip = getHostByName( getHostName() );
Transferring it to another server, he began to display 127.0.0.1
It seems that getHostName () returns localhost, which in turn is converted to 127.0.0.1via getHostByName ().
Looking at other issues, it seemed like it $_SERVER['SERVER_ADDR']could solve the puzzle, but it also brings back127.0.0.1
Checking and finding the output from phpinfo()does not return any indication of the actual IP address of the machine.
Seriously, does anyone know of a bulletproof (simpler) way to get the ip address of a machine running a script? Why is it so difficult to obtain such fundamental data without reverse flips?
I really don't want to hardcode the ip address in the configuration file ...
source
share