How can I refresh the session during a POST request?

前端 未结 2 1090
梦如初夏
梦如初夏 2021-01-05 06:06

I\'m building an Ajax app in Symfony2 where a user logs in, and then from that point forward everything is handled by POST requests. After defining the session lifetime to 5

2条回答
  •  长发绾君心
    2021-01-05 07:01

    The lifetime of a session is it's maximum age. This is controlled via a cookie which has already been created and is not refreshed any longer from the server side (because the session is already established). You can just update this cookie manually and I think this will make it with symfony2.

    The probably easiest is to regenerate the session id w/o destroying the session:

    $this->get('session')->migrate();
    

    This should trigger an update on the session cookie.

    Probably related questions:

    • symfony2 session live time
    • Programmatically Set Session Lifetime in Symfony2

提交回复
热议问题