Search code examples
phpajaxcodeigniter-2session-cookies

codeigniter ajax how to not auto log out users


I'm using CodeIgniter for a website I'm working on, because the admin area uses AJAX requests to communicate with the server. The user could be working on something that does not need AJAX requests, so after a while of non-AJAX work when the user tries to send something with AJAX, it results in an error like this:

SyntaxError: Unexpected token < http://www.site.com/index.php

I check whether users are logged in or not on the server like this:

if(!isset($_SESSION['username'])){
    redirect('login');
}

I'm only using $_SESSION, not cookies. Do I have to use cookies or implement some JavaScript function that pings the server to keep it alive when user is idle, or both? Thanks in advance.


Solution

  • I didn't implement a solution for this error, but for however, is end up here loking for the same thing a good solution will be to use the jQuery-Idle plugin, i hope this helps anyone.