Check if Codeigniter session has expired with AJAX Check if Codeigniter session has expired with AJAX codeigniter codeigniter

Check if Codeigniter session has expired with AJAX


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.


Codeigniter session class has method which let us know about session expiry.

function your_method(){     $this->session->sess_read() === false ? echo "0" : echo "1";}