473,757 Members | 5,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Warning: headers already sent

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!
Jul 17 '05 #1
1 2447
While the city slept, None (ln*****@sypmat ico.ca) feverishly typed...
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

[etc]

As answered yesterday (or possibly the day before) and several times over
the last couple of weeks...

You cannot have ANY output AT ALL before you set sessions, write cookies or
send headers. That includes any HTML output. Move your session code to
before any output is sent and it should work, or at least, you shouldn't be
getting the errors you do at the moment! ;-)

Cheers,
Nige

--
Nigel Moss
http://www.nigenet.org.uk
Mail address not valid. ni***@DOG.nigen et.org.uk, take the DOG. out!
In the land of the blind, the one-eyed man is very, very busy!
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3173
by: Phyzlo | last post by:
Hello, I've recently started learning PHP and have a question. I tried running below script which can be found at http://se2.php.net/manual/sv/function.setcookie.php but I keep getting this message on my browser, why? Warning: Cannot add header information - headers already sent by (output started at /var/www/cookietest.php:2) in
4
14090
by: Bob | last post by:
Seem to have a problem ending a session. I get the following message. Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\xitami\xitami-24\app\webpages\logout.php:9) in C:\xitami\xitami-24\app\webpages\logout.php on line 10 Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at
19
7927
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache limiter - headers already sent in /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php on line 14
2
6223
by: samcode3 | last post by:
Hi, I would be thankfull if anyone could give me the solution for this header problem. There are no blank spaces at end as there is html code in end. I have used <?php session_start();?> in first line and in between am checking this for session. <?php if($_SESSION == "email"){ echo "username already taken. Please try another!"; $_SESSION="";} else if($_SESSION == "user"){ echo "Email exist. If you have registered then please login!";...
22
2225
by: Platero | last post by:
Hi, I've a stupid question but... The code is the following: if(($role!='tutor')&&(array_key_exists('tutor_id',$_GET))) { $possible_ids = array(2,6,7,8,9,10); $t_id = $_GET;
4
449
by: lucavilla | last post by:
If you go to http://europe.nokia.com/A4305060, fill the "Enter your product code:" field with the value "0523183" and press "Go" (the ending page URL varies because there's a variable session-ID in the URL-link associated to "Go") you will obtain this string: "Version: RM43_V1.10.030" Is it possible to have a string.php page that just display this string? how can I do it?
8
2397
by: mcserret | last post by:
I know this is a recurring problem that has been addressed here before, but even after reading all that has gone before, I am still stumped. I have a form that is designed to send data to a PHP page where is is to be validated then read into a MySQL table. Once that is done, the form is to send the user either back to the originating page, or to a logout page. I have several versions of this setup on my site that work well, so
2
2331
by: smartic | last post by:
I'm having problem with header redirection that is my code: <?php header("location:Redirecting.php"); exit; ?> //Then the HTML It give me an error
3
2847
by: mrosado | last post by:
Hi everybody, I have this problem.- The browser launch this two errors: Warning: session_start() : Cannot send session cache limiter - headers already sent (output started at /home/notasluz/public_html/administrador/Administrador.php:1) in /home/notasluz/public_html/administrador/verificaEntrada.php on line 2  Warning: Cannot modify header information - headers already sent by (output started at...
0
9297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10069
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9904
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7285
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3828
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.