By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,967 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,967 IT Pros & Developers. It's quick & easy.

session_start error

P: 5
I got message:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at E:\Program Files\Apache Group\Apache2\htdocs\openemr-2.9.0\interface\login\login_frame.php:4) in E:\Program Files\Apache Group\Apache2\htdocs\openemr-2.9.0\interface\globals.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at E:\Program Files\Apache Group\Apache2\htdocs\openemr-2.9.0\interface\login\login_frame.php:4) in E:\Program Files\Apache Group\Apache2\htdocs\openemr-2.9.0\interface\globals.php on line 3

What is wrong???
Thanks.
Oct 15 '08 #1
Share this Question
Share on Google+
5 Replies


P: 14
don't print anything before session start.so make session start as your first line
Oct 15 '08 #2

Markus
Expert 5K+
P: 6,050
Take this for example

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. echo "hello, world";
  4.  
  5. session_start();
  6.  
  7. ?>
  8.  
This would cause an error similar to the one you have. Changing around the statements would do rid of this error.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. session_start();
  4.  
  5. echo "hello, world";
  6.  
  7. ?>
  8.  
There can be NO output before your session_start() call. None!

Also, it would be helpful for us to see your code to help you.
Oct 15 '08 #3

P: 5
Thank you vetrib2w for such quick and helpful reply.
I did what you suggested and it really works.
Thanks again.
But I do not understand why worning appears if I print something before
START_SESSION().
Oct 15 '08 #4

Markus
Expert 5K+
P: 6,050
Because, my dear friend, for PHP to use sessions (cookies), it needs to send the data to the browser before anything else and it simply can't do that if you've already started output. Rules are rules.
Oct 15 '08 #5

Atli
Expert 5K+
P: 5,058
To be more specific.

To start a session, a session cookie must be set.
And to set a cookie, the cookie must be added to the Set-Cookie header of the HTTP response.

Once you start sending the *content* of the response, the headers are sent and any additional headers ignored. Which leads to the no content before session_start rule.

If you absolutely must start sending content before adding a header, then you could always use Output Buffering.
Oct 15 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.