Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Hi when I echo $_ENV['HOSTNAME'] from a PHP script it no longer works, it used to (I think my server hosting company has changed a setting but I cant think what)

When I run hostname from the command line I get the proper (expected) hostname, also when I do

php -r 'echo $_ENV["HOSTNAME"];'

I get the proper (expected) hostname as well.

Any ideas? Servers are running CentOS.

Thanks

share|improve this question

1 Answer 1

The availability of the ENV array indeed depends on the webserver configuration. Inspect the SERVER array or try using gethostname() instead.

share|improve this answer
    
Hi thanks for the reply. This is code that has worked and hasn't changed, it was happily using $_ENV for a while, I understand that the variables_order can affect this but I dont understand why the SERVER array would now have this value, how/where would this be defined on the server itself? –  sam Feb 14 '12 at 14:54
    
SERVER won't have HOSTNAME, as far as I can tell. I was suggesting that perhaps another variable, like HTTP_HOST, could be used instead. See this question: See this question: stackoverflow.com/questions/3780866/why-is-my-env-empty. Also, this list may come in handy: php-developer.org/wp-content/uploads/scripts/… –  Eduardo Ivanec Feb 14 '12 at 15:06
    
Hi, that would mean I need to change my code, I'm more interested in finding out what change would have caused this, if its in apache, php etc? –  sam Feb 14 '12 at 16:04
    
I'd say E is probably missing from variables_order in the appropriate php.ini. Is that right? –  Eduardo Ivanec Feb 14 '12 at 17:07
    
nah E is the first one EGPCS we dont have SERVER['HOSTNAME'] set either and nothing in the get, post and cookies :( –  sam Feb 14 '12 at 17:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.