Warning: Cannot modify header information

software development

#1

Hello all,

I am getting this and is driving me nuts. Maybe I am doing something really silly? Here is my code:

<?php /* * Created on Jan 25, 2007 * */ include('functions.php'); include('variables.php'); session_start(); header("Cache-control: private"); if ($_SESSION["access"] == "granted") { if($_SESSION["notice"]) { echo $_SESSION["notice"] . "\n"; $_SESSION["notice"] = ""; } if($_SESSION["error_message"]) { echo $_SESSION["error_message"] . "\n"; $_SESSION["error_message"] = ""; } $username = $_SESSION["username"]; $db = db_connect($dbname); $query = "SELECT * FROM $recipe_tablename"; $result = mysql_query($query); $top = <<<TOP ADMIN SECTION

Welcome, $username

Add a New Recipe Manage Categories, Chefs, Wines Log Off

Current Recipes in Database

TOP; $bottom = <<<BOTTOM BOTTOM; echo $top . "\n"; // This is the middle part, where we display categories and recipes // Set default category (id=1), if this is the first time to display the form if(!$_POST["categories"] && $_SESSION["categories"]) {$_POST["categories"] = $_SESSION["categories"];} if(!$_POST["categories"] && !$_SESSION["categories"]) {$_POST["categories"] = $_SESSION["categories"] = 1;} echo " \n"; $result = mysql_query("SELECT * FROM categories") or die( "Cannot retrieve categories" ); if(mysql_num_rows($result)) { echo "

Category: \n"; echo " \n

"; while($row = mysql_fetch_row($result)) { if($row[0] == $_POST["categories"]) {$selected = "SELECTED";} else {$selected = "";}; echo " $row[1]\n"; } echo " \n"; // Display the recipes in the category $recipes = mysql_query("SELECT * FROM $recipe_tablename WHERE category_id = {$_POST["categories"]}"); echo " \n"; while ($row = mysql_fetch_assoc($recipes)) { echo " " . " " . " \n"; } } else { echo "No Categories Exist Yet\n"; } echo "
{$row['recipe_name']}Edit RecipeDelete Recipe
\n"; echo " "; echo "\n" . $bottom; } else // Not logged in! $_SESSION["error_message"] = "You must be loggin in to access this part of the site. Please provide your credentials below."; header("Location: login.php"); ?>

The error occurs at the header() part and is started at the echo $top part

Any help greatly appreciated. BTW, this only happens on the DH server only. I ran it on another and it was working flawlessly. Is there a special seeting that I need to turn on/off for this to work on DH too?


#2

php header function should be started before html header.

You cannot echo anything before php header function

Save [color=#CC0000]$97[/color] (max discount) on dreamhost plans by using promo code: [color=#CC0000]97CRAZY[/color].