error message with sessions

Reply

Join Date: Jun 2005
Posts: 9
Reputation: symoore22 is an unknown quantity at this point 
Solved Threads: 0
symoore22 symoore22 is offline Offline
Newbie Poster

error message with sessions

 
0
  #1
Jun 16th, 2005
Im getting an error with my website when i try using sessions.

Im new to it so im probably doing something stupid

http://www.bluetipdvd.co.uk/cart.php
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:

thanks

simon

Code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<? 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;
window.open(url,'welcome','width=200,height=200');
}
</script>
</head>
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: error message with sessions

 
0
  #2
Jun 16th, 2005
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.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1
Reputation: boonkoon is an unknown quantity at this point 
Solved Threads: 0
boonkoon boonkoon is offline Offline
Newbie Poster

Re: error message with sessions

 
0
  #3
Jun 29th, 2005
put your 'header("Cache-control: private")' at the top of your code. The header() should run before all the html code.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: error message with sessions

 
0
  #4
Jun 29th, 2005
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 http://www.tgreer.com/class_session_php.html
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC