PHP sessions - stuff to check when things goes wrong.

1 minute read

There is too much information about problems with sessions in PHP, every dude got it's own problem and it's own solution.
The probability that the problem you experiencing is the same is very low. 
So here is what my little (and very annoying) google journey came up to:



  • You must call session_start(); on each page
  • If you use the header('Location: blabla'); you should use relative url to keep preserve session 
  • some people say before using the header action you need to call  session_write_close(); - I'm not using it.
  • session_write_close(); could be the reason to your problems, cause after calling it you can't modify the session (in the current http context), that was my problem.
  • on php docs, they say that "Session ID is not passed with Location header even if session.use_trans_sid is enabled. It must by passed manually using SID constant."
So first make sure you use session start, if you passed this search for voodoos like  session_write_close() in the middle of your infrastructure and remove them.

If I didn't help, continue the journey.

Comments