duanbi6522 2013-09-24 18:39
浏览 27
已采纳

如何让用户会话比其他会话更长?

I've been trying to implement a "remember me" option to my login screen for the last hours, with no success. Can someone give me a little help? =D

I'm using cakephp 2.3.9 in a apache2/mysql 5.5/ubuntu 12.10 server. In "login()" method, inside my users controller, I've added the code:

if ($this->Auth->login()) {
 if($this->request->data('Usuario.remember')==="1"){
  CakeSession::write('Session.timeout', '144000');//100 dias
 }
 return $this->redirect($this->Auth->redirect());
}

I was hoping it would make that particular user session bigger than usual, but it seems that it was applied to all users. I'm using cakephp's default auth component. Can someone show me what I'm doing wrong and what should I do? Thanks in advance ;]

  • 写回答

1条回答 默认 最新

  • doudou6050 2013-09-24 18:50
    关注

    I'm unaware of any to do this with the way you're approaching it. PHP session timeout lengths are a server-wide setting defined in your PHP.ini under session.gc_maxlifetime.

    The way I personally would approach this would be to overwrite the session handler you're using, and rather than using the PHPSESSID cookie, create yourself your own cookie where you have control over the cookie expiry time. This could then hold a custom Session ID which your overwritten session handler could then pick up and use to authenticate the user.

    CakePHP isn't something I'm too familiar with so I can't give you too much advice in the integration.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计