still losing session userdata across a redirect |
That's exactly what I thought too. I changed something while following all the directions that now makes it work. I don't think it was the reversal of writing to to session data and redirect. The main changes I made were
a) changed all controllers to upper case b) used urlencode and base64encode to get rid of the @ in the email address before writing to userdata c) changed the sess_save_path The sess save path is still $config['sess_save_path'] = APPPATH.'cache'; But now my debugger is not working. When I check with Web Server Debug Validation if fails with a 404 error.
proof that an old dog can learn new tricks
(12-02-2017, 01:42 PM)skunkbad Wrote: I don't think anyone else has mentioned it, but I've learned that there can be problems with the order that you set session data and do the redirect. I always set the redirect before writing to the session. I've had problems changing that order in the past. I must not understand what you mean by "set the redirect". What I think when I read "set the redirect before writing to the session" is code like this. PHP Code: redirect('somewhere'); Which is nonsense since the CI function redirect() does not return meaning the next line of code will never have a chance to execute. So, what do you mean? (12-04-2017, 03:17 PM)dave friend Wrote:(12-02-2017, 01:42 PM)skunkbad Wrote: I don't think anyone else has mentioned it, but I've learned that there can be problems with the order that you set session data and do the redirect. I always set the redirect before writing to the session. I've had problems changing that order in the past. I use PHP's header function, which does not use exit. Years ago I was having problems with a redirect and session combination, and I read somewhere that the redirect needs to be done before the session write, so I've been doing it that way ever since. That's all I know, and if it's wrong then I don't know much
12-05-2017, 12:09 PM
(This post was last modified: 12-05-2017, 12:10 PM by PaulD. Edit Reason: minor edits )
Does it help if you use 'refresh':
PHP Code: $_SESSION['item'] = 'xyz'; I know this will not help you, but I have never had a problem with session setting and redirecting. In fact I use it quite often with flash data. However, 'refresh' might be completely irrelevant to your problem, this is not an area I claim any expertise in. Sorry. Paul
(12-04-2017, 08:58 PM)skunkbad Wrote: I use PHP's header function, which does not use exit. Years ago I was having problems with a redirect and session combination, and I read somewhere that the redirect needs to be done before the session write, so I've been doing it that way ever since. That's all I know, and if it's wrong then I don't know much My assumption - that you were using the CI helper function redirect() - was the source of my confusion. I don't know if it's right or wrong but if it works then who am I to blow against the wind? That said, I'm at a complete loss as to how doing this PHP Code: header('Location: http://www.mysite.com/someotherpage.php'); would produce results different than this PHP Code: $_SESSION['item'] = 'xyz';
(12-05-2017, 12:09 PM)PaulD Wrote: Does it help if you use 'refresh': In the context of redirect() 'refresh' vs 'location' should be irrelevant. Both options produce redirect headers but the 'refresh' option can be time-delayed. In CI however, the 'refresh' option sets the delay to 0 (zero) making the refresh header effectively the same as the location header. However, I don't think that 'Refresh' is actually part of the http spec But AFAIK, it is supported by most (all?) browsers. Conceivably, results could vary by browser. In that light maybe 'refresh' is best avoided.
Yea, no kind of redirect should have any effect on sessions. If it ever did, that was rather a coincidence.
(12-01-2017, 08:49 AM)richb201 Wrote: I changed the past for cookies to: $config['sess_save_path'] = 'c:\xampp\htdocs\sub_crud\session_cookies'; This is solved the problem for me. Spent 2 days to figure this out
I got a similar issue where session are lost after a redirect.
I finally resolved this issue by change : redirect($page); To: redirect($page, "refresh"); |
Welcome Guest, Not a member yet? Register Sign In |