Page 1 of 1

Get $_SERVER['SERVER_ADDR'] as 192.168 instead of 127.0.0.1?

Posted: Sat Feb 14, 2009 2:30 pm
by JAB Creations
I'm trying to get the $_SERVER['SERVER_ADDR'] as 192.168.abc.xyz though it keeps coming up at 127.0.0.1. The reason is I'm trying to make the base element echo out the server's IP on a local network so I don't have to change the IP manually every time the network changes. Obviously if I try to load the page up on a different system then it will attempt to load the files adding the base element's href attribute's value as being on the same system instead of the server. I've tried messing around in the hosts file (system32\drivers\etc) however nothing seemed to work there. All the threads on forums I keep coming across always burn out before anything useful. Suggestions please?

Re: Get $_SERVER['SERVER_ADDR'] as 192.168 instead of 127.0.0.1?

Posted: Sat Feb 14, 2009 2:37 pm
by Benjamin
Hmm, maybe you have to change the IP in httpd.conf.

Re: Get $_SERVER['SERVER_ADDR'] as 192.168 instead of 127.0.0.1?

Posted: Sat Feb 14, 2009 2:54 pm
by JAB Creations
Looks like you're correct though I'm not sure what dynamic value to place here...

Code: Select all

ServerName localhost:80
#ServerName 192.168.1.101:80
#ServerName 127.0.0.1:80
I'm reading about the servername though I've never really found Apache's documentation understandable though if I find the answer I'll obviously post it here.

Re: Get $_SERVER['SERVER_ADDR'] as 192.168 instead of 127.0.0.1?

Posted: Sat Feb 14, 2009 3:45 pm
by JAB Creations
Pilot error! I was not requesting from a network IP however once I did everything seemed to work fine. I commented out all my hosts and httpd.conf changes, restarted the Apache service, and everything runs clean. When I changed my network IP it still ran smoothly so I've resolved the issue.