Welcome Guest, Not a member yet? Register   Sign In
Redirecting To Login Page If Session Expired during or before Ajax request is made
#11

[eluser]d2burke[/eluser]
Not sure if anyone is still having an issue with this...but i was so i'll post my work-around.

What I did was place a bit of code at the beginning of each method that is called via AJAX to determine whether the user was still logged in:


Code:
$is_logged_in = $this->session->userdata('is_logged_in');
if(!$is_logged_in){
    echo 'INVALID';
    return false;
}

The above simply sends a message back and stops running if the user is not logged in anymore.

Then in my Js file, I first check the response to determine if it equals 'INVALID' and if so I do a simple Js refresh:

Code:
if(response=='INVALID'){
    location.reload(true);
    return false;
}

The refresh then sends them seamlessly back to the login page. This works perfectly for me. I'm sure it can be re-written to be more efficient, and if someone has that idea then I'd love to update it, but for now, this works well Smile


Messages In This Thread
Redirecting To Login Page If Session Expired during or before Ajax request is made - by El Forum - 05-17-2011, 10:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB