1

How to maintain codegnitor session with AJAX?

My session expires when I call more AJAX requests. So how can I maintain both the AJAX request and the session?

Jørgen R
  • 10,568
  • 7
  • 42
  • 59
Paras Dalsaniya
  • 99
  • 2
  • 10

1 Answers1

0

use this builtin function to check if ajax call or not and then take desired action.

if($this->input->is_ajax_request()){
    //action...
}else
{
    $this->session->sess_destroy();
}

you can find some answer here CodeIgniter Session Disappear Bug?

your answer also available here Codeigniter session bugging out with ajax calls which is :

class MY_Session extends CI_Session {
    public function sess_update()
    {
        $CI = get_instance();

        if ( ! $CI->input->is_ajax_request())
        {
            parent::sess_update();
        }
    }
}
Community
  • 1
  • 1
Imran Qamer
  • 2,253
  • 3
  • 29
  • 52