简体   繁体   中英

Cakephp redirect after session expires

我在一个网站上使用CakePHP,我想知道会话期满后如何自动重定向?

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'
            )
        )
    )
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM