PHP session destroyed / lost after header

前端 未结 6 1984
无人共我
无人共我 2020-12-10 02:39

I\'ve got a script that sets some session values before redirecting to / using header().

I\'ve read many posts about the $_SESSION

相关标签:
6条回答
  • 2020-12-10 03:15

    In the interest of closing this question, we had concluded it was a problem with the server configuration, not surprising considering the host is well known for this kind of thing.

    0 讨论(0)
  • 2020-12-10 03:23

    I've never seen any session related issues due to using location headers - are you sure you're calling session_start on both pages?


    Hmm... this answer made a lot more sense before you added the session_start bits above, and mentioned the fact that you were sure you were using session_start. :-)

    0 讨论(0)
  • 2020-12-10 03:23

    You don't need to start session_start() in each page. cuz untill your browser is closed the same session remains for the entire path you have specified in php.ini

    0 讨论(0)
  • 2020-12-10 03:28

    After the Header redirect you need to exit the PHP script:

    header("Location: /");
    exit();
    
    0 讨论(0)
  • 2020-12-10 03:31

    header must be sent before session close

    session_regenerate_id(true);
    
    header("Location: /");
    // the header must be sent before session close
    session_write_close(); // here you could also use exit();
    
    0 讨论(0)
  • 2020-12-10 03:37

    just put exit; after header :D I solved by this

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