5

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

BlueFox
  • 53
  • 4

1 Answers1

3

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

Ruben Müller
  • 471
  • 2
  • 4
  • Ahhh yes, i had missed this completely! Perfect answer, and the additional code is a great help aswell. Thank you very much!! – BlueFox Jan 24 '12 at 11:45
  • As a further note to this, should the setting of userdata also be inside of the IF statement? As it is at the moment it will unset key session data. – BlueFox Jan 24 '12 at 11:58
  • In fact i have now removed the logout function entirely from auth.php Line 310 [link](https://github.com/ilkon/Tank-Auth/blob/master/application/controllers/auth.php#L310). Tried and tested works great. – BlueFox Jan 24 '12 at 12:10
  • i have tried with the above code, but the sessions are not working, it is not redirecting to home page when i am logging, but remain in the same login page – lalith222 Dec 15 '12 at 09:51