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 advanceinstaller对话框设置
    • ¥100 正常上网,内部网页无法打开
    • ¥15 组件库引入并使用在若依框架未展示
    • ¥149 关于#使用python 的Flash Echarts+ajax+mysql动态数据实现饼图#的问题,请各位专家解答!
    • ¥15 RichTextBox中追加文本时报错
    • ¥15 关于c语言的学习问题
    • ¥15 activity升级到flowable工作流act_ge_bytearray的草稿json数据复制到act_de_model 的model_editor_json的脚本
    • ¥15 cvi使用CreateThread创建线程时,出现存储空间不足无法处理此命令的错误
    • ¥15 求苹果推信imessage批量推信技术
    • ¥15 ubuntu 22.04 系统盘空间不足。隐藏的docker空间占用?(相关搜索:移动硬盘|管理系统)