joe92 joe92 - 12 days ago 5
PHP Question

PHP Notice: Undefined index: HTTP_HOST in /var/.../script.php on line 8

I am getting the same error in my apache error log as described in this question. The only difference is that I am using $_SERVER as described in the answer.

Line 8 is:

if(strstr($_SERVER['HTTP_HOST'],'127.0.0.1'))


The same error appears for line 59 which has the exact same conditional. It's a conditional to tell the website whether we are in sandboxing or not. As far as I can tell nothing bad is happened except it is clogging up the apache error log.

Does anyone know why this is happening and how to fix it? The PHP version is 5.3.10. The server is running Ubuntu 12.04.

Thank you.

Answer

The manual implies this index may not always be set http://php.net/manual/en/reserved.variables.server.php

Contents of the Host: header from the current request, if there is one.