duanfei8897 2013-10-04 21:24
浏览 64
已采纳

CodeIgniter会话与cookie

I have an application which is under development in CodeIgniter. But I have a problem with session management. By default, sessions in CodeIgniter are saved onto the visitor's machine, which means they last about two hours without being deleted on the close action (visitor closing the browser); while all of us know that PHP keeps session as long as the browser runs, and as it is closed by the user, it will kill it.

My problem: I love CI session style, but for some particular purposes and in some instances I need PHP session style (being deleted when browser is closed). CI provides me such option but I do not like to delete all sessions when the browser is closed. I need only two or three session values to be removed on browser shut down. Should I use go back to PHP pure session for the instances where sessions must be delete on browser shut down? Or CI has some options for customizing the lifespan of session for individual vlaues?

thanks in advance

  • 写回答

1条回答 默认 最新

  • dscdttg4389 2013-10-04 21:30
    关注

    You can change/set the value of sess_expiration config variable in the file application/config/config.php - the default is 7200 seconds (2 hrs). Set it to zero to never expire. Another useful variable is sess_expire_on_close. More details at http://ellislab.com/codeigniter/user-guide/libraries/sessions.html

    If you want to customize across different types of sessions, you can create your own Session class based on CI code, you can create a new class or extend class CI_Session and just make it read from a different set of config variables. https://github.com/EllisLab/CodeIgniter/blob/develop/system/libraries/Session/Session.php

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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料