Welcome Guest, Not a member yet? Register   Sign In
how to destroy a session and immediately create a new one?

Hi all,
I basically want to do the following:
When a user comes to a site, he can interact with the site and some data will be stored in the session. If he chooses to login, the session data that has been stored till now will be cleared and new session will be started afresh.

Now I cannot use unser_userdata function because some of the userdata's keys are generated on the fly and the key could be anything. So my best bet, as I see is to clear the session somehow and set the username etc for the loggedin user. Then the user can start afresh.

I have the following code, which is not working :

function validateUser()
$email = $this->input->post('Email');
$password = $this->input->post('Password');
$isAuthenticUser = $this->Login_model->validateUser($email, $password);

// If the user authenticated properly
if ($isAuthenticUser == TRUE)
// Destroy whatever you have in the session

// Set the username in the new session

If I execute this code and then immediately reload the page, the user is not shown as logged in. If I remove the destroyUserSession() call, then the user is shown as logged in.

Interestingly, if I print the session just after destroying it, it seems it is not destroyed at that time. Maybe some sort of delayed destruction which is causing the problem?

Any help is appreciated.

Messages In This Thread
how to destroy a session and immediately create a new one? - by El Forum - 04-15-2010, 04:32 AM

Theme © iAndrew 2016 - Forum software by © MyBB