Link to home
Start Free TrialLog in
Avatar of nawazmakda
nawazmakdaFlag for India

asked on

Why this Undefined index: HTTP_HOST

Why I am getting this warning?

So plz tell me how can I fix this problem.?


[19-May-2009 16:01:54] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/home.php on line 14
[19-May-2009 16:01:54] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/header.php on line 13
[19-May-2009 16:01:54] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/header.php on line 37
[19-May-2009 16:05:19] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/home.php on line 14
[19-May-2009 16:05:19] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/header.php on line 13
[19-May-2009 16:05:19] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/header.php on line 37
[19-May-2009 16:08:45] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/home.php on line 14
[19-May-2009 16:08:45] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/header.php on line 13
[19-May-2009 16:08:45] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/header.php on line 37
[19-May-2009 16:12:13] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/home.php on line 14
[19-May-2009 16:12:13] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/header.php on line 13
[19-May-2009 16:12:13] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/header.php on line 37
[19-May-2009 16:15:39] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/home.php on line 14
[19-May-2009 16:15:39] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/header.php on line 13
[19-May-2009 16:15:39] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/header.php on line 37
[19-May-2009 16:19:04] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/home.php on line 14
[19-May-2009 16:19:04] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/header.php on line 13
[19-May-2009 16:19:04] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/header.php on line 37
[19-May-2009 16:22:32] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/home.php on line 14
[19-May-2009 16:22:32] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/header.php on line 13
[19-May-2009 16:22:32] PHP Notice:  Undefined index:  HTTP_HOST in /home/<myname>/public_html/esh/header.php on line 37

Thank you.
<a href="http://<?php echo $_SERVER['HTTP_HOST']; ?>

Open in new window

Avatar of shobinsun
shobinsun
Flag of India image

Hi,

try this:

<a href="http://<?php echo $_SERVER['HTTP_HOST'];?>">
Hi,

you should use something in between start and end of href tag like:

<a href="http://<?php echo $_SERVER['HTTP_HOST'];?>">something</a>
chk if ur register_globals are turned on???

HTH
Manavsi
HTTP_HOST is not always defined in some cases...

do a var_dump on $_SERVER to check what is getting populated.
Avatar of nawazmakda

ASKER

use the following code and chk if the HTTP_HOST is defined...

HTH
Manavsi
<?
var_dump($_SERVER);
 
?>

Open in new window

hi Manavsi,
Thaks again..! for replying me

doing  var_dump on $_SERVER It gives output that  HTTP_HOST is already defined and also HTTP_REFERER is set too.


anyway..
From some where I found to do that,

Those messages 'PHP Notice' are not error messages as such.

Edit php.ini file and find this line

error_reporting = E_ALL & ~E_NOTICE

This will turn off notices but still show any errors.

Hope this helps,



Thanks for you support Guys..
hey i dont get it... though its still a notice.. ur purpose of getting the value from the HTTP_HOST will not work right...???

Tell me if i'm right or wrong???

Manavsi
heyyyyy Manavsi

no my purpose was that why I am getting those type of error messages..?
what is the reason behind it?

how do I Solve this problem and avoid to get those error messages?
Hi,

// how do I Solve this problem and avoid to get those error messages?

Ans: you need to set your php.ini file to not display notices. displaying warnings and errors, but not notices is the most typical setup and what most people code for.

error_reporting  =  E_ALL & ~E_NOTICE

also, if you still run into problems, you may have to turn on register_globals. it's not as secure as having it off, but again, most servers are setup this way:

register_globals On

once you have made the changes in your php.ini file, restart your web server


Regards
Hi,

You can use another option:

try:

getenv('HTTP_HOST')

Instead of

$_SERVER['HTTP_HOST']


Regards
it also could be due to Apache version... if you are using apache there is an intermittant bug in older versionf of Apache that cause it not to be set but as above post should get it from that... getenv() that is if $_SERVER does not work...
ASKER CERTIFIED SOLUTION
Avatar of nawazmakda
nawazmakda
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sdf