Hello, I am a total newbie to PHP and programming in general. I am playing
around with a PHP / MySQL shopping cart script which I found at
http://www.macromedia.com/devnet/mx/.../php_cart.html. When
I try to start a session or create a cookie, I get the following errors.
Warning: Cannot send session cache limiter - headers already sent (output
started at /wrapper_head2.p hp:27) in /cart.php on line 13
Warning: Cannot add header information - headers already sent by (output
started at /wrapper_head2.p hp:27) in /cart.php on line 14
Warning: Cannot add header information - headers already sent by (output
started at /wrapper_head2.p hp:27) in /cart.php on line 14
Warning: Cannot add header information - headers already sent by (output
started at /wrapper_head2.p hp:27) in /cart.php on line 14
Warning: Cannot add header information - headers already sent by (output
started at /wrapper_head2.p hp:27) in /cart.php on line 14
Here is the beginning of my PHP script for the shopping cart. I haven't
changed much from the original tutorial.
<?php
// This page contains the connection routine for the
// database as well as getting the ID of the cart, etc.
$dbServer = "blanked";
$dbUser = "blanked";
$dbPass = "blanked";
$dbName = "blanked";
function ConnectToDb($se rver, $user, $pass, $database)
{
// Connect to the database and return
// true/false depending on whether or
// not a connection could be made.
$s = @mysql_connect( $server, $user, $pass);
$d = @mysql_select_d b($database, $s);
if(!$s || !$d)
return false;
else
return true;
}
function GetCartId()
{
// This function will generate an encrypted string and
// will set it as a cookie using set_cookie. This will
// also be used as the cookieId field in the cart table
if(isset($_COOK IE["cartId"]))
{
return $_COOKIE["cartId"];
}
else
{
session_start() ;
setcookie("cart Id", session_id(), time() + ((3600 * 24) * 30));
return session_id();
}
}
//call the page header
include("wrappe r_head2.php");
switch($_GET["action"])
{
case "add_item":
{
AddItem($_GET["id"], $_GET["qty"]);
ShowCart();
break;
}
case "update_ite m":
{
UpdateItem($_GE T["id"], $_GET["qty"]);
ShowCart();
break;
}
case "remove_ite m":
{
RemoveItem($_GE T["id"]);
ShowCart();
break;
}
default:
{
ShowCart();
}
}
function AddItem($itemId , $qty)
{ ... the functions in the case are defined from here on.
Here are the contents of the wrapper_head2.p hp page, which it tells me is
causing the problem.
<?
echo "
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\">
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
<title>Title</title>
<link rel=stylesheet type=\"text/css\" href=\"blue.css \">
</head>
<body>
<table width=\"100%\" border=\"0\" cellpadding=\"0 \" cellspacing=\"0 \">
<tr>
<td>
<table width=\"100%\" height=\"100%\" border=\"0\" cellpadding=\"0 \"
cellspacing=\"0 \">
<tr>
<td>
";
//call header page
include("header .html");
echo "
</td>
</tr>
<tr>
<td>
";
//call horizontal menu
include("strip. html");
echo "
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width=\"100%\" border=\"0\" cellpadding=\"0 \" cellspacing=\"0 \">
<tr>
<td background=\"im ages/stripsha.gif\" height=\"4\" width=\"120\"
bgcolor=\"#D7DE EC\"></td>
<td background=\"im ages/stripsha2.gif\" height=\"4\"></td>
<td background=\"im ages/stripsha3.gif\" height=\"4\" width=\"140\"
bgcolor=\"#ECF3 FF\"></td>
</tr>
<tr>
<td width=\"120\" valign=\"top\" bgcolor=\"#D7DE EC\">
";
//call vertical menu
include("menu.h tml");
echo "
</td>
<td valign=\"top\">
<table width=\"100%\" height=\"100%\" border=\"0\" cellpadding=\"0 \"
cellspacing=\"0 \">
<tr>
<td valign=\"top\" height=\"400\">
<div align=\"center\ ">
";
?>
I am guessing that my problem is with the order of the code in my cart.php
page. Several online forums said to check for blank lines and white space
before and after the PHP <? ?> tags, because session_start has to be called
before anything else. I checked with Notepad, and can't find any space
outside of the PHP tags in cart.php, wrapper_head2.p hp, or any of the html
files called by wrapper_head2.p hp. Can someone please give me some
suggestions as to what I am doing wrong?
Thank you!