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> - 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;,'welcome','width=200,height=200');

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.

Thanks, boonkoon. I missed that, symoore22. Yes, both your session_start() and any header() lines must be BEFORE you actually output any of the HTML document.

That session mgmt and password protection class and article are ready now at