I’m using codeigniter for my web application which is having user registration feature. And also i am using ajax in most of the places for loading the page. The problem is, if some function is called through ajax to load a page and if session does not exists, it is not redirecting to the login page. But it is working when we visits the same URL through browser(It is redirecting to the login page). What should i do to resolve this problem?
This is the code for checking session we are using.
$userid=$this->phpsession->get('userid');
if(!($userid))
{
redirect('home','refresh');
}
In your controller detect if it is an ajax request:
In ajax detect the response and redirect to the login page: