How to extend session cookie lifetime in symfony?

When accessing the session data on the server side, a value is set modified_time, so the extension of its validity in the future.

However, this does not happen for PHPSESSIDcookies. While server-side session expiration is increasing, cookie expiration is not. If the cookie expires, the user will lose the session - he will not have the session ID that will be sent when the request is sent.

Can I specify Symfony\Component\HttpFoundation\Session\Sessiona cookie extension?

  • Can this be done for the same session id? Or will we have to regenerate it (it seems inefficient to make many requests for many X users)?
  • Do I have to install it myself manually (without taking into account the principles of OOP).

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

+4
source share
1 answer

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

# session configuration
session:
    cookie_lifetime:    3600

From the doc:

cookie_lifetime

type: integer default: null

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

More information in the document here.

+3
source

Source: https://habr.com/ru/post/1671368/


All Articles