Welcome Guest, Not a member yet? Register   Sign In
Strange issue with Sessions + cookies
#1

[eluser]dallen33[/eluser]
I posted a topic earlier where I had issues with cookies expiring prematurely. I was using the database feature of Session (sess_use_database = true).

However, if I change sess_use_database to false, my cookie works properly. It doesn't expire (it hasn't in the past 5 days). I'm wondering if there's a bug with CI Sessions?
#2

[eluser]treeface[/eluser]
Could you tell us a little more about the problem? Are you using ajax on your site? If you do, there is a known problem with the session class where it will update the session token that's stored in the db, but since it's an ajax call, PHP cannot update the session token stored in the browser cookie. So what happens is on the next request, the tokens will not match and sess_destroy() will be called.

The way to figure out if this is the source of your problem (assuming you're using ajax) is to change your session cookie expiration time to something like 15 seconds. Then load a page where you can press a button (or whatever) to make an ajax call. Wait 16 seconds before you make the call (so it tries to refresh the token), then reload the page you're on. If you've signed out, you'll know the reason why.

If you do all that and get the results described, come back here and let me know and I'll be able to help you out.
#3

[eluser]dallen33[/eluser]
Hi treeface,

Nope, not using any AJAX. All I have is a simple form for clients to send us files. The form gets submitted to itself. They enter their name, company, email, phone, sales rep, and details of the file. Below the form is a button that says "Remember my info". If it's checked, a cookie gets created so the next time they visit the page, all their personal info is filled in.

Here's my code in controller app.php:
Code:
$checked = (isset($_POST['remember']))?true:false;

if ($checked):    
    $sessdata = array(
                    'fullname'    => $this->input->post('fullname'),
                    'company'    => $this->input->post('company'),
                    'email'        => $this->input->post('email'),
                    'phone'        => $this->input->post('phone'),
                    'sales'        => $this->input->post('sales'),
                    'remember'    => TRUE
                   );
    
    $this->session->set_userdata($sessdata);
    $data['success'] = 'Successfully submitted and remembered!';

That makes a cookie, and it works just fine. But if I enable the use database in config, the session gets recreated if I do any of the following:

1. Quit browser, reopen (this isn't consistent, but it does happen)
2. Restart computer (again, inconsistent)
3. Go back to the page a few hours later
4. Go back to the page the next day

And, like I said, all of those COULD recreate the session. That's the weird thing, it's not consistent.
#4

[eluser]treeface[/eluser]
Could you perhaps do var_dump()s of the userdata before and after you set it? That might shine some light on what's changing, if anything.




Theme © iAndrew 2016 - Forum software by © MyBB