Marco Gasi
asked on
redirect to login page
Hi everybody.
I have a web application where the user must be logged in: no problem here. In each page I check if the user is logged and if it is not he is redirected to the login page.
But within the application, many operations involve the use of Ajax calls to several php scripts. The problem is this: if the user keep the page opened enough without doing anything, the session expires so the user is no more logged in, but if he come back to the app and click a button to do something the page continue loading without do anything.
My solution has been to put the check even in php scripts:
What am I doing wrong?
I have a web application where the user must be logged in: no problem here. In each page I check if the user is logged and if it is not he is redirected to the login page.
But within the application, many operations involve the use of Ajax calls to several php scripts. The problem is this: if the user keep the page opened enough without doing anything, the session expires so the user is no more logged in, but if he come back to the app and click a button to do something the page continue loading without do anything.
My solution has been to put the check even in php scripts:
if ( !isset( $_SESSION[ 'user_id' ] ) )
{
echo json_encode('expired');
}
and then, in javascript:var response = JSON.parse(data);
if ( response === 'expired' ) {
window.location.href = globalURL;
return;
}
but this has no effect: the page remains with loading spinner and stays there.What am I doing wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER