Expire session automatically and detect if the session has expired in Codeigniter

后端 未结 5 1649
粉色の甜心
粉色の甜心 2021-02-06 13:37

I\'ve seen plenty of questions here about my topic but it seems I still haven\'t found my answer. What I\'m actually looking for is when the session expires the user will be aut

5条回答
  •  清歌不尽
    2021-02-06 14:19

    You can check user's session by making the ajax call and wrap it into the setInterval jquery's function like

    setInterval(function() {
      // Do something every 1 minute 
    $.ajax({
    type : 'POST',
    url  : ''
    success : function(data){
    if(data){
       //your session is not expired
    }else{
       //your session is already expired
     window.location.href="your url"; // or you can redirect from here also
    } 
    });
    }, 60000);
    
    
     //This function checks your session 
     function check_session(){
        $id = $this->session->userdata('id');
       if($id ){
             echo 1;
       }else{
             echo 0;
       redirect('your register controller');//redirect from here or you can redirect in the ajax response
       }
    
      die();
     }
    

    Hope it makes sense

提交回复
热议问题