Prevent session expired in PHP Session for inactive user

后端 未结 5 576
傲寒
傲寒 2020-12-05 03:17

I have a problem with my application: my application has many forms and need about 1 hour to finish this form because the form is dynamic (can add other forms). The problem

5条回答
  •  抹茶落季
    2020-12-05 03:29

    Changing session.gc_maxlifetime using ini_set should work as long as you change the option before calling session_start. So doing the following should work:

    ini_set('session.gc_maxlifetime', 36000);
    session_start();
    

    You can also change that option in other contexts (see ChazUK’s answer).

    But I wouldn’t set the cookie’s lifetime to a fixed value but make the session’s cookie a real session cookie that lasts until the browser session is ended (i.e. on browser close). You can do this by setting session.cookie_lifetime to 0.

    Do also consider that PHP’s session expiration model is a little quirky as the lifetime calculation is based on the session data’s last modification date.

提交回复
热议问题