Connecting Tech Pros Worldwide Forums | Help | Site Map

session_start error

Newbie
 
Join Date: Oct 2008
Posts: 5
#1: Oct 15 '08
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.
Newbie
 
Join Date: Aug 2008
Posts: 14
#2: Oct 15 '08

re: session_start error


don't print anything before session start.so make session start as your first line
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#3: Oct 15 '08

re: session_start error


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.
Newbie
 
Join Date: Oct 2008
Posts: 5
#4: Oct 15 '08

re: session_start error


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().
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#5: Oct 15 '08

re: session_start error


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.
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,747
#6: Oct 15 '08

re: session_start error


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.
Reply