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
Session warning
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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.
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.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
As long as your code starts like this...
... 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...
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.
Code: Select all
<?php
session_start();
// continue on...
?>Code: Select all
<?php
session_start();
// continue on...
?>Code: Select all
<?php
session_start();
// continue on...
?>