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

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

Postby JAB Creations » Sat Feb 14, 2009 3:30 pm

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

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

Postby Benjamin » Sat Feb 14, 2009 3:37 pm

Hmm, maybe you have to change the IP in httpd.conf.
Image
User avatar
Benjamin
Site Administrator
 
Posts: 6862
Joined: Sun May 19, 2002 10:24 pm

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

Postby JAB Creations » Sat Feb 14, 2009 3:54 pm

Looks like you're correct though I'm not sure what dynamic value to place here...

Syntax: [ Download ] [ Hide ]
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 7:44 pm
Location: Sarasota Florida

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

Postby JAB Creations » Sat Feb 14, 2009 4:45 pm

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


Return to PHP - Code

Who is online

Users browsing this forum: Google [Bot] and 6 guests