开发者

Cakephp redirect after session expires

I'm using CakePHP in on开发者_如何学Goe website and I was wondering how can I automagically redirect when the session has expired?


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.


using your components ($components) you choose the login specifics details and lougout too such as the redirect page when the session close.

public $components = array(
    'Session'=>array(
        'timeout' => 620
    ),'Auth' => array(
        'loginRedirect' => array(
            'controller' => 'pages',
            'action' => 'display',
            'home'
        ),
        'logoutRedirect' => array(
            'controller' => 'users',
            'action' => 'login'
        ),
        'authenticate' => array(
            'Form' => array(
                'passwordHasher' => 'Blowfish'
            )
        )
    )
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜