views:

77

answers:

2

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, user information and all other session variables are gone.

What's the best way to approach this problem?

A: 

The best way to approach any problem is debugging based on the knowledge.

In case of sessions, debugging involves HTTP sniffing to watch HTTP headers and cookie among them. What server does set, what browser return. HttpWatch from the ad on this page could help.

Hope your both scripts are on the same domain/server.

Col. Shrapnel
Yes all scripts on the same server.
well go for the HTTP debugging.posting here redirect code would be helpful too
Col. Shrapnel
A: 

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 :-)

Eric
p.s. what does your redirect() function look like?
Eric
I didn't get it yet, but you're right. I simplified it and the session is persistent. Which means it's something in the code itself. I'll look for it now.Thank you.
My pleasure. FWIW I usually find this to be a quick way to home in fast on a bug when I'm not entirely sure where the exact problem lies: I just start hacking away at the code with a machete, (temporarily) removing large chunks of functionality and seeing if the bug still exhibits itself.
Eric