Im getting an error with my website when i try using sessions.

Im new to it so im probably doing something stupid

error message:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/bluetip/public_html/cart.php:4) in /home/bluetip/public_html/cart.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /home/bluetip/public_html/cart.php:4) in /home/bluetip/public_html/cart.php on line 5

Can anybody suggest what is wrong with this:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<? session_start();
header("Cache-control: private");?>
<title>BlueTipDVD.co.uk - Number 1 site for dvds free delivery on all orders</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="bluetipdvd.css" rel="stylesheet" type="text/css">

<script language="javascript">
function longdescription(ID) {
url = 'proddetail.php?ID='+ID;

13 Years
Discussion Span
Last Post by Troy

Hey, symoore22! The problem is that session_start() has to write a cookie to the user's computer, and PHP can't write COOKIES after you start the output because once the HTTP headers are sent, cookies can't be sent. (They are sent in the headers.)

So you just need to put session_start() at the very top of your code--or at least before any browser output.

By the way, I have just finished work on what I think is a really slick PHP session mgmt class that also integrates authentication (password-protecting pages). One major advantage of my session class is you don't have to worry about the session timing out on your users unexpectedly. I plan to post it as an article soon. I'd take some guinee pigs now.


put your 'header("Cache-control: private")' at the top of your code. The header() should run before all the html code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.