Search code examples
session-variablesphp-7.2

How to start a session again after a session_write_close()


I have code in which I use sessions, and after modifying session variables, session_write_close() is called so that the session data lock is released. Now at another point in the same script, I need to make modifications to the session variables again. However, if I call session_start() again, the "session headers already sent" error shows up. Is there any way to modify session variables again without getting this error?


Solution

  • You can call session_start(), and session_write_close as many times as you want, it wouldn't cause that error.

    This error means that you've already provided some output before attempting to write to the session. You need to make sure you don't echo out anything before attempting to write to the session.