$_SERVER['HTTP_HOST'] returning blanks

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
PingLeeQuan
Forum Commoner
Posts: 58
Joined: Tue Sep 03, 2002 8:08 am

$_SERVER['HTTP_HOST'] returning blanks

Post by PingLeeQuan »

I have 2 server that run the same code. The code uses 2 deferent databases depending on which server the code is hosted (i.e. test and production). I used the $_SERVER['HTTP_HOST'] to find the server in question but my echo kept returning blank. I checked the register_globals and it is turned on

any ideas
thanks
--quan
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

We do the same thing based on the $HTTP_SERVER_VARS['SERVER_NAME'].

John M
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

Very strange. Does "phpinfo();" show that HTTP_HOST is blank, too?
PingLeeQuan
Forum Commoner
Posts: 58
Joined: Tue Sep 03, 2002 8:08 am

Post by PingLeeQuan »

OK... I am confused.. I thought the manual said the $HTTP_SERVER_VARS is deprecated and that we should be using the $_SERVER.

I ran phpinfo(); and i got the right stuff in the server name parameter

I also ran $HTTP_SERVER_VARS['SERVER_NAME'] I also got the right result.

I guess I was going by what the manual was saying

Thanks guys...


this is what the manual said
PHP Superglobals
$GLOBALS
Contains a reference to every variable which is currently available within the global scope of the
script. The keys of this array are the names of the global variables. $GLOBALS has existed since PHP
3.
$_SERVER
Variables set by the web server or otherwise directly related to the execution environment of the
current script. Analogous to the old $HTTP_SERVER_VARS array (which is still available, but
deprecated).
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

What version of PHP are you running? The "_SERVER" superglobal is only available for PHP 4.1.0 and later.

Also, you mentioned that "SERVER_NAME" on your phpinfo() page was correct. What about "HTTP_HOST" on the phpinfo() page? Are both present and equal?

I agree with you - I wouldn't want to use deprecated globals if I could help it.
PingLeeQuan
Forum Commoner
Posts: 58
Joined: Tue Sep 03, 2002 8:08 am

Post by PingLeeQuan »

Rob: You got a point there i am using PHP 4.0.4.pl1... all the information the phpinfo() function produced is correct...

I guess i was having such a problem because of the version number.

Thanks again Rob / john M
--quan
Post Reply