There are two corresponding settings that control the session lifetime.
First session.cookie-lifetime . This is the cookie lifetime, which by default is 0, which means that the cookie is destroyed when the browser is closed. By increasing this variable, you can set a longer life. This applies to server time, so you need to consider the time differences on your clients' machines and on your server. Assuming they were the same, setting the option, i.e. 3600 means that the session will expire in an hour. If you want to keep the session for a very long time, you will increase this number.
However, this is not enough. There is also session.gc-maxlifetime , this is the time after which the session data is considered garbage in the storage and destroyed. This is different from session.cookie-lifetime because this option checks the last access time of the session data, so it refers to the time the session data was last used (i.e. when the last user was active). Even if you set session.cookie-lifetime to a high value, this will not be enough because session.gc_maxlifetime is usually relatively low ( 1440 is the default value, which is only 24 minutes).
Despite the fact that you can set these parameters as relatively high values ββand work with them, I would recommend not to do this, as this will leave a lot of unnecessary session data hanging in your session store due to the GC does not collect the actual ones (which also increases the likelihood that someone will capture a session in a system that is not properly protected). The best approach is to remember me a cookie. Basically, you assign a user ID and some authentication token that you store in the database for each user (this means that someone does not fake cookies) in a cookie, and give it a long service life. In the initialization code of your application, you will verify that the user is logged in. If he / she is not logged in, you will check if the cookie is set to remember me. If so, you pull the user out of the database based on the user ID in the cookie, and then check the authentication token in db is the same as in the cookie. If they match, you simply create a session and automatically register the user.
source share