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

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

报告相同问题?

悬赏问题

  • ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题