Page 1 of 1

Session warning

Posted: Thu May 11, 2006 11:03 pm
by EltonSky
Hello guys,
When I try to use session_start(), I got warning :
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/c/ctian/.HTMLinfo/learn/sessTest.php:2) in /home/c/ctian/.HTMLinfo/learn/sessTest.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/c/ctian/.HTMLinfo/learn/sessTest.php:2) in /home/c/ctian/.HTMLinfo/learn/sessTest.php on line 3

Can anybody tell me what does it mean, how can i handle them?

Cheers,

Elton

Posted: Thu May 11, 2006 11:20 pm
by alex.barylski
It means you have already sent headers to you browser...

Don't echo or have any HTML code before those function calls...either that or buffer your output...

Cheers :)

Posted: Thu May 11, 2006 11:59 pm
by EltonSky
Thanx for reply,

Do u mean my session is working and I should ignore that warning ? I use session_start() at the very beginning of the page actually.
Can u clarify a bit ?

REGARDS,

Elton

Posted: Fri May 12, 2006 1:24 am
by RobertGonzalez
You need to make sure that absolutely nothing, not even a blank white space, is sent to the browser before the call to session_start(), unless you are using output buffering. If anything gets sent to the browser before a call to session_start, you get the headers already sent warning.

PS, Warnings are not for ignoring. If you get one, fix it. Then continue to code in peace knowing that you are awesome for not cutting corners or being lazy.

Posted: Fri May 12, 2006 2:53 am
by EltonSky
Hi Everah,

Thank u.
This what i did:
<?php session_start();
?>
<HTML>
<HEAD>
<title>
.....

I think it 's already on the top, right?


REGARDS,

Elton

Posted: Fri May 12, 2006 10:18 am
by RobertGonzalez
As long as your code starts like this...

Code: Select all

<?php
session_start();
// continue on...
?>
... and it is not being included in another file, you should be fine. However, take a look at the next two pieces of code and see if you can spot the problem...

Code: Select all

  <?php
session_start();
// continue on...
?>

Code: Select all


<?php
session_start();
// continue on...
?>
Even that white space at the beginning of the PHP tag causes problems. If you are certain that your session call is appropriately placed, then the problem might not be code but PHP configuration or server configuration related.