【问题标题】:Can CodeIgniter sessions and regular sessions co-exist?CodeIgniter 会话和常规会话可以共存吗?
【发布时间】:2013-09-26 22:50:57
【问题描述】:

CodeIgniter 用户指南 2.1.4 版这样说:

注意:Session 类不使用原生 PHP 会话。它生成自己的会话数据,为开发人员提供更大的灵活性。

(https://www.codeigniter.com/userguide2/libraries/sessions.html)

我无法找到关于 CI Session 是否替换原生会话,或者仅仅是一种替代方法并且它们实际上同时共存的明确直接解释,其中在这种情况下,技术上可以同时使用两者。

不是人们想要,但它会避免一些事情。

提前致谢。

【问题讨论】:

    标签: php codeigniter session


    【解决方案1】:

    根据用户指南,

    会话如何工作?

    When a page is loaded, the session class will check to see if valid session data exists in the user's session cookie. If sessions data does not exist (or if it has expired) a new session will be created and saved in the cookie. If a session does exist, its information will be updated and the cookie will be updated. With each update, the session_id will be regenerated.

    因此 CI 使用 cookie,它与 PHP 的本机会话是分开的。

    还可以选择使用数据库,模仿 PHP 的本机会话,但在数据库而不是文件系统上。但是它很容易出现一个已知的错误,这里有一个例子:codeigniter session expires frequently

    简而言之,它们是完全独立的,如前所述,是的,它们可以同时共存。不过,只有当您通过 PHP 的本机方法手动创建会话时。

    【讨论】:

    • 谢谢。你能告诉我如何识别通过 CI VA 设置会话数据的代码 sn-p。通过原生 php 设置会话数据?
    • @Maxcot 我个人没有使用过原生 PHP 会话(一定会喜欢框架!),但似乎 PHP 既有会话对象(php.net/manual/en/class.sessionhandler.php)又有一系列以会话开头的函数...喜欢session_start() (php.net/manual/en/ref.session.php)
    猜你喜欢
    • 2011-08-09
    • 1970-01-01
    • 1970-01-01
    • 2011-01-01
    • 2013-09-22
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多