I'm creating a Helpdesk system, sometimes a user get more than two hours without using the system and then return when the session has expired, but the last loaded page remains on the screen (a form, for example) and the user can use it normally, but when he submits the form he is redirected to the login page (it's ok), but the user loses data entered.
I want to create an AJAX function that checks if the session has expired or not. That function should be performed using setTimeout() or setInterval().
I've tried using the "sess_expiration" but it seems that this value does not reset on page load, i.e. after ending the appointed time (7200 by default) it forces the session expiration.
2
votes
2 Answers
4
votes
You can do it like this
$.ajax({
type : 'POST',
url : '<?php echo site_url('controllername/methodname')?>'
success : function(data){
if(data){
//session available
}else{
// expired
}
});
And controller method
function methodname(){
$user_id = $this->session->userdata('user_id');
if($user_id){
echo 1;
}else{
echo 0;
}
}
You can wrap ajax request in function and return the result everytime with TRUE or FALSE. Moreover setInterval can call this function for checking session.