tags:

views:

32

answers:

4

Doing a shopping cart application using session. it was working fine but suddenly today a problem arrived whenever im trying to add a 2nd item the first one is removed and it gives the following warning..

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/matadije/public_html/cat_process.php:2) in /home/matadije/public_html/cat_process.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/matadije/public_html/cat_process.php:2) in /home/matadije/public_html/cat_process.php on line 3

the first 3 lines of my code is as follows:

<title></title>
<?php
session_start();
+3  A: 

You are outputting <title></title> before starting the session, this means that all HTTP headers are already sent and it's impossible to add a session cookie to the response. Move your code up so it looks like:

<?php
session_start();
?>
<title></title>
halfdan
thanks a lot!!!
Tiya
+3  A: 

The session_start() function must be called before any output if you use cookies.

In your case, it seems that you use cookies and the <title></title> output prevent the session_start() to be called.


Notes on the PHP.net documentation :

Note:

To use cookie-based sessions, session_start() must be called before outputing anything to the browser.


Resources :

Colin Hebert
method != function
halfdan
@halfdan, I do too much java :P it's corrected
Colin Hebert
+2  A: 

Session has to be initialized before you print anything (like HTML).

Change your code to

<?php session_start(); ?>
<html>
...

and it will work.

RaYell
+1  A: 

It should be the first line of the page.

vinothkumar