gpt4 book ai didi

php - PHP 如何知道何时删除 session ?

转载 作者:可可西里 更新时间:2023-11-01 00:10:32 25 4
gpt4 key购买 nike

我认为 session 存储在客户端,因为 session 在浏览器关闭时被删除。然而,今天有人告诉我这不是真的, session 存储在服务器上。

那么 session 如何知道浏览器何时关闭,以便 session 被删除?

最佳答案

事实并非如此。有两个因素在起作用:

  • lifetime of the cookie在客户端;此 cookie 包含 session ID。它与 session 数据本身没有任何关系

    The manual probably doesn't stress this enough:

    This has nothing to do with lifetime of a session

    Whatever you set this setting to, it won't change how long sessions live on your server.

    This only changes HTTP cache expiration time (Expires: and Cache-Control: max-age headers), which advise browser for how long it can keep pages cached in user's cache without having to reload them from the server.

  • 服务器端 session 数据的生命周期;通过使用来自客户端的 session ID 进行查找来“激活” session 。它的生命周期通过 session garbage collection settings discussed here 控制.

    一位评论者在 session.cache_expire 文档页面上发帖,大概是在谈论 session 数据:

    What most people also don't know, is that most Linux distributions (Debian and Ubuntu for me atleast) have a cronbjob that cleans up your session dir using the value set in the global /etc/php5/php.ini (which defaults to 24mins). So even if you set a value larger in your scripts, the cronbjob will still cleanup sessions using the global value.

    If you run into that situation, you can set the global value higher in /etc/php5/php.ini, disable the cronjob or even better, do your own session cleanup in a non-systemwide directory or a database.

    如您所见,在区分 session 跟踪和 session 数据存储时,社区中存在很多混淆。

关于php - PHP 如何知道何时删除 session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8693934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com