简体   繁体   中英

Symfony 4 session expire too soon

My php session with Symfony 4.0 expire too soon even if I set it up for several days in config/packages/framework.yaml .

framework:

{...}
session:
    handler_id: ~
    cookie_lifetime: 604800
{...}

When the user complete the signin process, he can navigate on the website and, if he return after few minutes, he doesn't need to signin again.

But if he return after 1 or 2 hours (don't know precisely) the session is expired and he must sign in again.

One of the solution that seems worked, was to change what you see above in:

handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/sessions"
cookie_lifetime: 604800    

Unfortunately that solution solved the problem in the dev environment, but crashed the app once that I pulled the code on the server.

Problem solved .

The problem was save_path . Just use the parameters suggested in the official Symfony Documentation . In this way your cookies will be correctly stored.

session:
    handler_id: session.handler.native_file
    save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
    cookie_lifetime: 604800

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM