Hello I am working on getting data from database by sending a piece of value using the getJSON method of JQuery library, to a PHP function which fetches data from the database. The data is then put into an name:value pair array and is json encoded and returned/echoed. This would help jQuery to populate the required HTML elements with the data from database. This works fine for me.
My problem is to have login redirection when the user is not logged in or when the session is expired. I am working with cakePHP, so I use their Auth component to check if the user logged in
if(isset($this->Auth->User('id')))
{
//do reqd
}
else
{
$this->Session->setFlash(__('Session Expired.', true));
$this->redirect(array('controller'=>'users','action' => 'login'),null,true);
}
And when the the session is expired, the login page is actually displayed as html in the json response, rather than the whole page being redirected. I know it is coming as a json response as I can see the login page displayed in the HTML part of firebug's console application. I am not sure if there needs to be any other type of redirection.