How do I resolve the problem of losing a session after a redirect in PHP?
Recently, I encountered a very common problem of losing session after redirect. And after searching through this website I can still find no solution (although this came the closest).
Update
I have found the answer and I thought I'd post it here to help anyone experiencing the same problem.
Make sure a new session is created properly by first destroying the old session.
Yes, session_start() is called twice. Once to call the unset and destroy commands and a second time to start a fresh session.
you should use "exit" after header-call
I had the same problem and found the easiest way. I simply redirected to a redirect .html with 1 line of JS
instead of PHP
I hope this helps.
Love Gram
Another possible reason:
That is my server storage space. My server disk space become full. So, I have removed few files and folders in my server and tried.
It was worked!!!
I am saving my session in AWS Dynamo DB, but it still expects some space in my server to process the session. Not sure why!!!
Just for the record... I had this problem and after a few hours of trying everything the problem was that the disk was full, and php sessions could not be written into the tmp directory... so if you have this problem check that too...
If you are using Laravel and you experience this issue, what you need is to save your session data before redirecting.