2016-08-22 85 views
1

我正在使用CakePHP 2.4.3,现在它在大约30分钟处于不活动状态后将我注销。我希望会话持续更长时间(或者像Facebook这样的无限可能)即使我离开网站(不关闭浏览器)几个小时左右。如何使CakePHP中的会话无限(或者至少更长时间,即使在非活动状态下)?

我试过的这些工作过下面的应用程序/配置/ core.php中,但没有:

测试#1:

Configure::write('Session', array(
     'defaults' => 'php', 
     'timeout' => 60, // The session will timeout after 60 minutes of inactivity 
     'cookieTimeout' => 4320, // The session cookie will live for at most 3 days, this does not effect session timeouts 
     'checkAgent' => false, 
     'autoRegenerate' => true, // causes the session expiration time to reset on each page load 
    )); 

测试#2:

Configure::write('Session', array(
     'defaults' => 'php', 
     'timeout' => 2160, // 36 hours 
     'ini' => array(
      'session.gc_maxlifetime' => 129600 // 36 hours 
     ) 
    )); 

测试#3:

Configure::write('Session', array(
      'defaults' => 'php', 
      'cookieTimeout' => 0 
    )); 
Configure::write('Security.level', 'medium'); 

我不确定当cakephp网站上的脚本本身不起作用时(测试2),现在发生了什么事情。我登录后,检查其他网站,然后在一小时后回到网站,然后注销。如何使CakePHP中的会话无限(或者至少更长时间,即使在非活动状态下)?

+0

请记住,PHP会在超时达到之前刷新会话。这可能发生在共享主机和大量流量上。我通常使用自己的目录来存储会话:'session_save_path('/ path/to/www/session.collection')'。您必须自己清理它们(例如,使用cron作业) –

回答

0

把这个在你的后过滤行动的AppController:

$这个 - >会话级>更新();

这会将会话cookie更新为无限。

否则,你试试下面的代码,

'Session' => [ 
     'defaults' => 'database', 
     'timeout'=>2441, 

    ], 

添加超时按您的要求。

使用会话数据库,创建一个会话表,它将存储会话

可能它会帮助你

+0

afterFilter在控制器操作运行并呈现后调用,因此如果我暂时不使用站点(没有控制器运行),则会话将不会更新还是对的?并且在我几个小时后回来时最终也会过期。 – Leah

0

将这个下面的代码到你的项目文件core.php中

Configure::write('Session', array(
    'defaults' => 'php', 
    'timeout' => 30000, // The session will timeout after 30 minutes of inactivity 
    'cookieTimeout' => 1440, // The session cookie will live for at most 24 hours, this does not effect session timeouts 
    'checkAgent' => false, 
    'autoRegenerate' => true, // causes the session expiration time to reset on each page load 
)); 
+0

这与我的测试#1不一样吗? – Leah

相关问题