I’m using CodeIgniter with CodeIgniter sessions that are stored in a MySQL database.
I need to do a multi-page redirect as shown below:
`some_form.php` -> `processing.php` -> `another_form_based_on_processing.php`
Everything’s okay going from some_form.php -> processing.php.
But when I redirect the page from processing.php -> another_form_based_on_processing.php, I lose the session. An entirely new session is started, and user information and all other session variables are gone.
What’s the best way to approach this problem?
Sometimes (if the user doesn’t have cookies enabled, for example), PHP has to pass the session ID from page to page in the URL… perhaps that’s the case here, and when you redirect from the 2nd page to the 3rd (and the user is logged out), that’s because the session ID isn’t being carried along. Just an idea.
One strategy to debug this that might be easier than watching HTTP headers is to (temporarily) simplify your code dramatically. Right now you say the hop from page 1 to page 2 is okay, but 2 to 3 is where the session is lost… so change page to 2 to immediately redirect to page 3. If, after that change, the user is still logged in on page 3 (i.e. the session is preserved), that means something else in your page 2 code is destroying the session.
Good luck, and to echo Col. Shrapnel’s comment above, posting code/debugging results may help us to help you more 🙂