CodeIgniter Forums
still losing session userdata across a redirect - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: still losing session userdata across a redirect (/showthread.php?tid=69481)

Pages: 1 2 3


RE: still losing session userdata across a redirect - richb201 - 12-04-2017

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. 


RE: still losing session userdata across a redirect - dave friend - 12-04-2017

(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');
$_SESSION['item'] = 'xyz'

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?


RE: still losing session userdata across a redirect - skunkbad - 12-04-2017

(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 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');
$_SESSION['item'] = 'xyz'

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?

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 Smile


RE: still losing session userdata across a redirect - PaulD - 12-05-2017

Does it help if you use 'refresh':
PHP Code:
$_SESSION['item'] = 'xyz'
redirect('somewhere''refresh'); 

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


RE: still losing session userdata across a redirect - dave friend - 12-05-2017

(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 Smile

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');
$_SESSION['item'] = 'xyz'

would produce results different than this

PHP Code:
$_SESSION['item'] = 'xyz';
header('Location: http://www.mysite.com/someotherpage.php'); 



RE: still losing session userdata across a redirect - dave friend - 12-05-2017

(12-05-2017, 12:09 PM)PaulD Wrote: Does it help if you use 'refresh':
PHP Code:
$_SESSION['item'] = 'xyz'
redirect('somewhere''refresh'); 

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

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.


RE: still losing session userdata across a redirect - Narf - 12-06-2017

Yea, no kind of redirect should have any effect on sessions. If it ever did, that was rather a coincidence.


RE: still losing session userdata across a redirect - Ishan - 12-14-2017

(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';

>>A cookie with the 'secure' flag can't be sent over plain HTTP (must be HTTPS).
No prob here. I have secure set to false.

>>A cookie set for domain foo.bar won't be sent to foo.baz, naturally.
I have this set to : $config['cookie_domain'] = ''; What should it be set to?

>>A cookie set for path /foo won't be sent to /bar, also naturally.
This is set to $config['cookie_path'] = '/';
>>You should also check/show your cookie settings.

Where is this? Do you mean?


Code:
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;

This is solved the problem for me. Spent 2 days to figure this out


RE: still losing session userdata across a redirect - jvandal - 09-16-2019

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");