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

[eluser]spot0n[/eluser]
Thanks all,
it works now. Here is what I did :
JQuery file :
$("#loginButton").click(function() {
$.post('/login/logoutUser',
function(data) {
$.post('/login/validateUser',
{ Email: $("#email").val(),
Password: $("#password").val()},
function(data){
location.reload(true);
});
});

});

$("#logoutButton").click(function() {

$.post('/login/logoutUser',
function(data){
location.reload(true);
}
);
});

Basically call the logout function which will destroy the session. Then call the login function after reloading.

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

function logoutUser()
{
// Logout the user. Unset the session user name and the rest of the data
$this->Login_model->destroyUserSession();
}

and finally
Model :
function validateUser($email, $password)
{
$results = $this->db->get_where('Users', array('Email' => $email, 'Password' => md5($password)));
if ($results->num_rows()> 0)
{
// Set the username in the session
$this->Login_model->setSessionUser($email);
}
}

function setSessionUser($email)
{
$userRow = $this->db->get_where('Users',array('Email' => $email))->result();

$this->session->set_userdata("UserName", $userRow[0]->FirstName);
$this->session->set_userdata("UserID", $userRow[0]->UserID);
$this->session->set_userdata("LoggedIn", TRUE);
}

function destroyUserSession()
{
if ($this->session->userdata('HasOrdered') || $this->session->userdata('LoggedIn'))
{
$this->session->sess_destroy();
redirect('/Login/logoutUser');
}
}
Have tested it on localhost and is fast enough. On server - don't know.


Messages In This Thread
how to destroy a session and immediately create a new one? - by El Forum - 04-17-2010, 02:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB