如何在Symfony中延长会话cookie的生存期? [英] How to extend session cookie lifetime in Symfony?

查看:72
本文介绍了如何在Symfony中延长会话cookie的生存期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在服务器端访问会话数据时,其 modified_time 会被设置,因此将其过期时间延长到将来.

On accessing session data on the server side, its modified_time gets set, therefore extending its expiration time into the future.

但是, PHPSESSID cookie不会发生这种情况.虽然服务器端的会话数据有效期延长了,但cookie有效期却没有延长.如果Cookie过期,则用户将丢失其会话-发送请求时,他将没有会话ID.

However, this does not happen for PHPSESSID cookie. While session data expiration on the server side is extended, the cookie expiration is not. If the cookie expires, the user will lose his session - he will have no session ID to give when sending a request.

有什么方法可以告诉 Symfony \ Component \ HttpFoundation \ Session \ Session 延长cookie的有效期吗?

Is there any way to tell Symfony\Component\HttpFoundation\Session\Session to extend the cookie expiration date?

  • 可以为相同的会话ID完成此操作吗?还是我们必须重新生成它(对于许多用户X许多请求似乎效率低下)?
  • 我应该手动设置它(不考虑OOP原则)

我找到了 $ request-> getSession()-> getMetadataBag()并尝试设置 stampNew(),但这似乎与 PHPSESSID cookie无关.

I've found $request->getSession()->getMetadataBag() and tried setting stampNew(), but this does not seem to interact with the PHPSESSID cookie.

推荐答案

您可以在会话密钥下的config.yml文件中进行更改,例如:

You can change in the config.yml files under the session key, as example:

# session configuration
session:
    cookie_lifetime:    3600

来自文档:

cookie_lifetime

cookie_lifetime

类型:整数默认值:空

这确定会话的生存期-以秒为单位.默认值value-null-表示来自的session.cookie_lifetime值将使用php.ini.将此值设置为0表示cookie为在浏览器会话期间有效.

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.

文档中的更多信息此处

这篇关于如何在Symfony中延长会话cookie的生存期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆