Welcome Guest, Not a member yet? Register   Sign In
Database Sessions losing Userdata?
#1

I'm trying to determine if this is something wrong in my setup or a possible bug in CI3. I'm working on a checkout process for a site in CI3. We're using database sessions, and - in this case - the Cart library. I'm seeing that during the session ID regeneration, it's creating the new session, but failing to transfer the existing userdata over (in this case - the contents of the cart). sess_regenerate_destroy is false, so it should keep the data.

Is anyone else experiencing this?

Code:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'id';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = true;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
Reply
#2

There's only one way for this to happen - if you've got ajax calls changing the session data (in this case your cart contents), it's possible that one such call is queued to execute after the request that triggers ID regeneration. Thus, the new session data is only written to the old session.

That or a PHP bug, as CI has no control over the regeneration mechanics; it just calls session_regenerate_id().
Reply
#3

Hmm. While the site does have it's share of AJAX going on, I experienced that this morning while visiting the site in a non-AJAX manner. The page stayed there, untouched, for a while as I was coding. Went back to refresh the page and found the data gone. Verified that a couple of times.

I didn't think it sounded like anything since I know the Session lib is using PHP's functions to do it. I'll have to take a closer look at the cart class in the AM and see if it's tieing itself to a specific session ID or something. And if it's too much of a pain - I guess I'll just start storing temporary transactions since I have all of the data needed for that. Hopefully it's something silly in my code.
Reply
#4

(02-08-2016, 10:24 PM)kilishan Wrote: Hmm. While the site does have it's share of AJAX going on, I experienced that this morning while visiting the site in a non-AJAX manner. The page stayed there, untouched, for a while as I was coding. Went back to refresh the page and found the data gone. Verified that a couple of times.

I didn't think it sounded like anything since I know the Session lib is using PHP's functions to do it. I'll have to take a closer look at the cart class in the AM and see if it's tieing itself to a specific session ID or something. And if it's too much of a pain - I guess I'll just start storing temporary transactions since I have all of the data needed for that. Hopefully it's something silly in my code.

Are you using the session for anything else, or just the cart?
Reply
#5

(02-08-2016, 10:48 PM)skunkbad Wrote: Are you using the session for anything else, or just the cart?

The cart and a logged in status is all.
Reply
#6

Not sure what's going on. I set the regenerate time to 60 seconds and stepped through the regenerate process (and the writes and reads that followed) several times using XDebug and it worked fine. As soon as I let it run on its own, not stepping through it, it clears the session data again. The only thing that I can think of at this point is that my stepping through it was keeping a session "alive" longer so things worked, or something like that. I did notice one of the times that I was following through that PHPStorm showed the session id changed, but nothing was updated in the database during that. IIRC, that was during the next read, but I'm unsure.

I don't have time to go down this rabbit hole any further at the moment, since I'm already tight on the deadline for this sprint, so will have to think of a different way. Wait - I might not be able to since we have to allow non-logged in users to have items in their cart. Hmm...
Reply
#7

Interestingly enough, files-based sessions don't lose the data when they regenerate. Wonder if it's something to do with read/write times to my local database?
Reply
#8

To be clear, it sounds like you lose your session at every session regeneration, but only when database sessions are implemented. Although you don't have time for it now, it would be a shame if you didn't figure out what the problem was, because this is a a show stopper of a bug and may effect many others. I hope when you've completed your work that you will come back to this and post a solution.
Reply
#9

Um, what data is there in the session after the regeneration? I got the impression that only your cart contents are somehow lost, but is it otherwise really and completely empty?

If it doesn't even have __ci_last_regenerate, then it's a write failure, but there already was a bug related to this that was fixed. Are you using the latest version?
If so, you'd at least be getting error messages for such failures ...
Reply
#10

(02-09-2016, 12:36 PM)Narf Wrote: Um, what data is there in the session after the regeneration? I got the impression that only your cart contents are somehow lost, but is it otherwise really and completely empty?

If it doesn't even have __ci_last_regenerate, then it's a write failure, but there already was a bug related to this that was fixed. Are you using the latest version?
If so, you'd at least be getting error messages for such failures ...

The only thing left in there is __ci_last_regenerate. Version reports as 3.1.0-dev, but it's probably been a couple of months since I've update CI core on this project. Was that a recent fix? If so, I'll update and see if that takes care of it.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB