gpt4 book ai didi

php - 如何在 Symfony 中延长 session cookie 的生命周期?

转载 作者:可可西里 更新时间:2023-10-31 23:15:54 26 4
gpt4 key购买 nike

在服务器端访问 session 数据时,它的 modified_time 被设置,因此将它的过期时间延长到 future 。

但是,这不会发生在 PHPSESSID cookie 上。虽然服务器端的 session 数据过期时间延长了,但 cookie 过期时间却没有。如果 cookie 过期,用户将失去他的 session - 他在发送请求时将没有可提供的 session ID。

有没有办法告诉 Symfony\Component\HttpFoundation\Session\Session 延长 cookie 过期日期?

  • 可以对同一个 session ID 执行此操作吗?或者我们是否必须重新生成它(对于许多用户 X 许多请求来说似乎效率低下)?
  • 我应该自己手动设置吗(无视 OOP 原则)

我找到了$request->getSession()->getMetadataBag()并尝试设置 stampNew(),但这似乎没有与 PHPSESSID cookie 交互。

最佳答案

你可以在 session key 下的config.yml文件中更改,例如:

# session configuration
session:
cookie_lifetime: 3600

来自文档:

cookie_lifetime

type: integer default: null

This determines the lifetime of the session - in seconds. The default value - null - means that the session.cookie_lifetime value from php.ini will be used. Setting this value to 0 means the cookie is valid for the length of the browser session.

文档中的更多信息 here

关于php - 如何在 Symfony 中延长 session cookie 的生命周期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42581996/

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