Cannot send session cache limiter - headers already sent
Posted: Tue Mar 18, 2008 7:09 am
Hi,
Newbie to php here sorry......
I am learning php from a book called sams teach yourself php, mysql and apache. The current topic i am running through is setting and using session cookies.
I get the following error....
Cannot send session cache limiter - headers already sent
From looking through various forums etc i have discovered that this is usually caused by un-necessary white space that dreamweaver may have added.
My code.....
My conclusion.....
After several hours searching for white space that DID NOT exist in my code i decided to try and remove my Document Type Definition (<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">)!
After removing the DTD the script ran fine with no errors.....so my question is....
Is it really advisable to run pages without declaring a DTD (document type definition)??
Newbie to php here sorry......
I am learning php from a book called sams teach yourself php, mysql and apache. The current topic i am running through is setting and using session cookies.
I get the following error....
Cannot send session cache limiter - headers already sent
From looking through various forums etc i have discovered that this is usually caused by un-necessary white space that dreamweaver may have added.
My code.....
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
session_start();
?>
<html>
<head>
<title>Storing an array with a session</title>
</head>
<body>
<h1>Product Choice Page</h1>
<?php
if (isset($_POST["form_products"])) {
if (!empty($_SESSION["products"])) {
$products = array_unique(
array_merge(unserialize($_SESSION["products"]),
$_POST["form_products"]));
$_SESSION["products"] = serialize($products);
} else {
$_SESSION["products"] = serialize($_POST["form_products"]);
}
echo "<p>Your products have been registered!</p>";
}
?>
<form method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<P><strong>Select some products:</strong><br>
<select name="form_products[]" multiple="multiple" size="3">
<option value="Sonic Screwdriver">Sonic Screwdriver</option>
<option value="Hal 2000">Hal 2000</option>
<option value="Tardis">Tardis</option>
<option value="ORAC">ORAC</option>
<option value="Transporter bracelet">Transporter bracelet</option>
</select>
<P><input type="submit" value="choose"/></p>
</form>
<p><a href="session1.php">go to content page</a></p>
</body>
</html>
After several hours searching for white space that DID NOT exist in my code i decided to try and remove my Document Type Definition (<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">)!
After removing the DTD the script ran fine with no errors.....so my question is....
Is it really advisable to run pages without declaring a DTD (document type definition)??