Undefined index: HTTP_HOST & Cannot modify header

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
Trevor_needs_help
Forum Newbie
Posts: 20
Joined: Thu Jan 29, 2004 8:13 am

Undefined index: HTTP_HOST & Cannot modify header

Post by Trevor_needs_help »

i have been tying for a day or so to fix the following error, i am still a newbie. i am getting the two following errors when i try to load the script.

Notice: Undefined index: HTTP_HOST in C:\Program Files\HTTPd\htdocs\current\html\view_print.php on line 36

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\HTTPd\htdocs\current\html\view_print.php:36) in C:\Program Files\HTTPd\htdocs\current\html\view_print.php on line 36

the script is

<?php


if (is_numeric ($_GET['pid'])) { // Make sure there's a meal ID.

require_once ('../mysql_connect.php'); // Connect to the database.
$query = "SELECT * FROM meal WHERE meal.meal_id = {$_GET['pid']}";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_ASSOC);
mysql_close(); // Close the database connection.

// Set the page title and include the HTML header.
$page_title = $row['meal_name'];
//include_once ('includes/header.html');

// Display a header.
echo "<div align=\"center\">
<b>{$row['meal_name']}</b> by

<br />{$row['size']}
<br />\${$row['price']}
<a href=\"add_cart.php?pid={$row['meal_id']}\">Add to Cart</a>
</div><br />";

// Get the image information and display the image.
if ($image = @getimagesize ("../uploads/{$row['image_name']}")) {
echo "<div align=\"center\"><img src=\"../uploads/{$row['image_name']}\" $image[3] alt=\"{$row['print_name']}\" />";
} else {
echo "<div align=\"center\">No image available.";
}
echo '<br />' . stripslashes($row['descripiton']) . '</div>';

include_once ('includes/footer.html'); // Require the HTML footer.

} else { // Redirect
header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
exit();
}

?>


ps thank you for replying and answersing my other probelm/posting :D
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

What version of PHP are you running, and are you running on Apache/IIS/etc,,and what version of the webserver is it?
Trevor_needs_help
Forum Newbie
Posts: 20
Joined: Thu Jan 29, 2004 8:13 am

Post by Trevor_needs_help »

web server = OmniSecure 3.0
php= 4.3.4
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Might be worth checking a <?php phpinfo() ?> page and possibly a var_dump($_SERVER); to see if HTTP_HOST is there (check PHP_SELF too whilst you're at it ;))
Trevor_needs_help
Forum Newbie
Posts: 20
Joined: Thu Jan 29, 2004 8:13 am

Post by Trevor_needs_help »

thanks
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

check if there are any spaces before <?php in your code, maybe that's why it says it can't send the headers
Trevor_needs_help
Forum Newbie
Posts: 20
Joined: Thu Jan 29, 2004 8:13 am

Post by Trevor_needs_help »

There was no vaule for PHP_SELF so i created a file called info.php and saved this the path of this now appears but i am still getting the header problem. any one got anymore ideas.
Post Reply