Welcome Guest, Not a member yet? Register   Sign In
still losing session userdata across a redirect
#21

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
Reply
#22

(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?
Reply
#23

(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
Reply
#24

(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'
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
Reply
#25

(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'); 
Reply
#26

(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.
Reply
#27

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

(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
Reply
#29

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




Theme © iAndrew 2016 - Forum software by © MyBB