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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

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

Post 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?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

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

Post by Benjamin »

Hmm, maybe you have to change the IP in httpd.conf.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

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

Post 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.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

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

Post 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.
Post Reply