Different session timeouts for admin and users in CAKEPHP 2.0. is it possible?

自古美人都是妖i 提交于 2019-12-12 13:34:34

问题


I am using cakephp 2.0 for developing a website. Site will contain only 2 types of users. Admin and users(customers). now I need to set session time out 10 minutes for customer and 1 hour for admin. is it possible ?. My core.php file contains the line like this,

Configure::write('Session', array(
    'defaults'      => 'php',
    'cookie'        => 'xyz',
    'timeout'       => 10,
    'checkAgent'    => false,
));

回答1:


It is more correct you do this condition in the AppController than to change your core.php this magnitude. You can make only this:

Configure::write('Session.timeout', 60);

And if you're using Acl, verify if user is admin using his own Acl method instead strripos.




回答2:


I added the following lines in core.php file. For quick fix

if(strripos($_SERVER['REDIRECT_URL'],"admin/")) {
   Configure::write('Session', array(
   'defaults' => 'php',
   'cookie' => 'xyz',
   'timeout' => 60,
   'checkAgent' => false,
));
}
else
{
   Configure::write('Session', array(
      'defaults' => 'php',
     'cookie' => 'xyz',
     'timeout' => 10,
    'checkAgent' => false,
    ));
}



来源:https://stackoverflow.com/questions/9476929/different-session-timeouts-for-admin-and-users-in-cakephp-2-0-is-it-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!