Page 1 of 1

Session Errors

Posted: Fri Nov 19, 2004 2:53 pm
by DudeBori82
What do these errors mean?


Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /data/sites/89545/checks.org/www/newsite/cartedit.php:4) in /data/sites/89545/checks.org/www/newsite/cartedit.php on line 5

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /data/sites/89545/checks.org/www/newsite/cartedit.php:4) in /data/sites/89545/checks.org/www/newsite/cartedit.php on line 5

Here is the code:

Code: Select all

<?php
<?
session_start();   
if ($_POST['Add'] == "add")
	{
	//is session array has been set, then check that the product we are adding has not been added beforehand
	if(isset($_SESSION['cart']))
		{
		$cartItem = sizeof($_SESSION["cart"]) + 1;
		$_SESSION["cart"][$cartItem] = array(  "Product_ID" => $_POST['Product_ID'], 
								"short_desc" => $_POST['short_desc'], 
								"style_ID"   => $_POST['style_color'],  
								"price_ID"   => $_POST['qty_price'],  
								"parts"      => $_POST['parts']
								);
		}
	}
	//if the session array has not been created beforehand create cart session array
else
	{
    	        
    	$cartItem = 0;    
		$_SESSION["cart"][$cartItem] = array(  "Product_ID" => $_POST['Product_ID'], 
									"short_desc" => $_POST['short_desc'], 
									"style_ID"   => $_POST['style_color'],  
									"price_ID"   => $_POST['qty_price'],  
									"parts"      => $_POST['parts']
									);

	}


?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Cart Edit</title>
</head>

<body bgcolor="bdbd8d" leftmargin="0" marginheight="0" marginwidth="0" topmargin="0">

<? $i=0;
while($i < sizeof($_SESSION["cart"])) {
echo $_SESSION["cart"][$i]["Product_ID"];
echo $_SESSION["cart"][$i]["short_desc"];
echo $_SESSION["cart"][$i]["style_ID"];
echo $_SESSION["cart"][$i]["price_ID"];
echo $_SESSION["cart"][$i]["parts"];
$i++;
} 

echo $_POST['Product_ID'];
echo $_POST['short_desc'];
echo $_POST['style_color'];  
echo $_POST['qty_price'];  
echo $_POST['parts'];
?>
?>
</body>
</html>

Posted: Fri Nov 19, 2004 3:11 pm
by MarK (CZ)
Try to search first... This was asked so many times before :wink:

To the problem: You can't send any output to the browser before starting 'session_start()'. Not even newlines (so delete those few empty rows on the beginning and you should be fine).

Posted: Sat Nov 20, 2004 8:24 pm
by josh