tags:

views:

798

answers:

4

Hey,

I am getting an undefined index on my config page and it reads:

Notice: Undefined index: SERVER_ADDR in inc/config .inc.php on line 3

Any idea on how I can fix that? I know its warning, but would still like to get at it. I am using it to check for the address whether to use my local or remote config settings.

Thanks,

Ryan

A: 

Have you tried getenv?

getenv('SERVER_ADDR')
Gumbo
A: 

You seem to be looking for $_SERVER["SERVER_ADDR"] in IIS which is not defined there.

Try $_SERVER['HTTP_HOST'] instead, it is set always as long as you force HTTP 1.1

Quassnoi
I believe that $HTTP_SERVER_VARS is deprecated; $_SERVER should be used instead.
Marc
Sure, my fault, copied wrong string :)
Quassnoi
+1  A: 

If you haven't done so, make sure you're accessing SERVER_ADDR using the $_SERVER array to obtain the value of SERVER_ADDR, which is an element of this array.

$_SERVER['SERVER_ADDR'];

If that doesn't work, it may mean that your server doesn't provide that information.

From PHP.net:

There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here.

Hope that helps.

Marc
Hey Marc,That is the variable I am using, I will try the other suggestions below. Thanks for your help.Ryan
Coughlin
A: 

Hey All,

I am using it in this context:

if ($_SERVER['SERVER_ADDR'] == '127.0.0.1' || $_SERVER['SERVER_NAME'] == 'localhost') {        

}
Coughlin
Can you tell us more about your environment? Webserver, etc.? It should be set in a standard PHP set. We might be also able to help you if we know what you are after.In general it's not save to 'rely' on env variables.
Till
Thats why I am confused, I am running PHP 5 on a linux, being hosted by GoDaddy - Shared Hosting.
Coughlin
Hey Till,I am using this for my config file to my database. If i am working locally, then use THIS config, else use my remote info.That is the main purpose of this conditional
Coughlin