session_start error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • willlen
    New Member
    • Oct 2008
    • 5

    session_start error

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

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

    What is wrong???
    Thanks.
  • vetrib2w
    New Member
    • Aug 2008
    • 14

    #2
    don't print anything before session start.so make session start as your first line

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Take this for example

      Code:
      <?php
      
      echo "hello, world";
      
      session_start();
      
      ?>
      This would cause an error similar to the one you have. Changing around the statements would do rid of this error.

      Code:
      <?php
      
      session_start();
      
      echo "hello, world";
      
      ?>
      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.

      Comment

      • willlen
        New Member
        • Oct 2008
        • 5

        #4
        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() .

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          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.

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            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.

            Comment

            Working...