How to keep session data using Codeigniter and Tank Auth

2.4k views Asked by At

I'm using Codeigniter and Tank Auth for a e-commerce website. I'm finding that if a customer puts items into the cart (using the Codeigniter built in cart class) and then registers on the site the session is lost along with their cart (I'm presuming it generates a new session for some reason instead of keeping the same session).

Has anyone come across this problem before? and is there a simply solution that I have overlooked.

Thanks

1

There are 1 answers

4
Ruben Müller On BEST ANSWER

As far as the most recent code looks like, the only place the hole session is deleted is in the logout() function, Tank_auth.php Line 118: https://github.com/ilkon/Tank-Auth/blob/master/application/libraries/Tank_auth.php#L118

The example usage of Tank Auth uses logout() in activate() and reset_email() - check your code for those methods. You could also change the Tank Auth logout function to something like this:

function logout($keep_session = false)
{
    $this->delete_autologin();

    // See http://codeigniter.com/forums/viewreply/662369/ as the reason for the next line
    $this->ci->session->set_userdata(array('user_id' => '', 'username' => '', 'status' => ''));

    if(!$keep_session)
        $this->ci->session->sess_destroy();
}

... and the use it like this: $this->tankauth->logout(true);