Troubleshooting “Warning: session_start(): Cannot send session cache limiter - headers already sent”

后端 未结 15 1675
醉酒成梦
醉酒成梦 2020-11-28 14:34

i am getting Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at error

<
相关标签:
15条回答
  • 2020-11-28 14:50

    Generally this error arise when we send header after echoing or printing. If this error arise on a specific page then make sure that page is not echoing anything before calling to start_session().

    Example of Unpredictable Error:

     <?php //a white-space before <?php also send for output and arise error
    session_start();
    session_regenerate_id();
    
    //your page content
    

    One more example:

    <?php
    includes 'functions.php';
    ?> <!-- This new line will also arise error -->
    <?php
    session_start();
    session_regenerate_id();
    
    //your page content
    

    Conclusion: Do not output any character before calling session_start() or header() functions not even a white-space or new-line

    0 讨论(0)
  • 2020-11-28 14:54

    use ob_start(); before session_start(); at top of your page like this

    <?php
    ob_start();
    session_start();
    
    0 讨论(0)
  • 2020-11-28 14:54

    Just replace session_start with this.

    if (!session_id() && !headers_sent()) {
       session_start();
    }  
    

    You can put it anywhere, even at the end :) Works fine for me. $_SESSION is accessible as well.

    0 讨论(0)
  • 2020-11-28 14:58

    use session_start() at the top of the page.

    for more details please read the link session_start

    0 讨论(0)
  • 2020-11-28 14:59

    Check any extra space before php tag.

    0 讨论(0)
  • 2020-11-28 15:00

    I had a website transferring from one host to another, it seemed to work fine on the old host but a few pages on the new host threw the error

    Warning: session_start(): Cannot send session cache limiter - headers already sent
    while I always kept the

     <?php
    session_start(); 

    at the top of the page no spaces and nothing inserted before

    it really bugged me that I stared every page with the session opening, and it worked on some pages and run through a bug on others I picked the pages that had the problems, backed them up, created new blank pages and simply copied and pasted the code as is, saved and uploaded and boom, problem gone!

    this is something you guys may need to consider, it may have been the encoding of the page, or something, not sure the exact source of the problem, but here is a fix to look at in case you guys run into a similar problem

    cheers!

    0 讨论(0)
提交回复
热议问题