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

图片转代码服务由CSDN问答提供 功能建议

我有一个正在CodeIgniter中开发的应用程序。 但我遇到会话管理问题。 默认情况下,CodeIgniter中的会话将保存到访问者的计算机上,这意味着它们可以持续大约两个小时而不会在关闭操作上被删除(访问者关闭浏览器); 虽然我们所有人都知道,只要浏览器运行,PHP就会保持会话,并且当用户关闭它时,它会终止它。

我的问题:我喜欢CI会话风格,但出于某些特定目的,在某些情况下我需要PHP会话风格(在浏览器关闭时被删除)。 CI为我提供了这样的选项,但我不想在浏览器关闭时删除所有会话。 我只需要在浏览器关闭时删除两个或三个会话值。 对于必须在浏览器关闭时删除会话的实例,我应该使用返回PHP纯会话吗? 或CI有一些选项可以自定义单个版税的会话生命周期?

提前感谢

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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

    打赏 评论

相关推荐 更多相似问题