Hello, I'm using CakePHP in one website and I was wondering how can I automagically redirect when the session has expired?
A:
mediaslave
2010-07-27 14:41:55
Sure, I know how this stuff works, my question was redirecting the user the very second that the session expires.
Juanda
2010-07-28 12:38:31
+3
A:
The session expiration is equivalent to the user logging out of your app. You can set variable
$this->Auth->logoutRedirect = array('component'=>'YourComponent','action'=>'YourAction');
and this will achieve similar results. You want set this in the beforeFilter() of your AppController.
If you want to redirect the user the very second the session expires, you will need to roll some custom javascript to achieve this effect. You could start with determining the approximate number of seconds until the session expires, passing it to a javascript setTimeout() call and firing a function which forces the user to logout. There are some caveats to this approach, but it would work just as well.
Michael
2010-07-27 14:56:26
Excelent, thanks a lot!It makes sense. However, what if the user has Javascript disabled?
Juanda
2010-07-28 12:37:26
Then you won't be able to force the user to log out. You'll just have to wait for them to make their next request from CakePHP. At that point, Cake will see the session has expired and force them to logout at that time, redirecting them to whatever you set in `$this->Auth->logoutRedirect`. :)
Michael
2010-07-28 18:35:48