Setting method: Find the file on the server through the "SESSION ID" in COOKIE; then set the validity period of cookie and session by using "session_set_cookie_params()" and "session_cache_expire()".
Recommended: "PHP Video Tutorial"
php sets the life cycle of SESSION
The problem I want to solve today, simply put, is to set the life cycle of SESSION. In fact, the problem is very simple. I just don’t know why. I use session_cache_expire(12*60); to close the browser. It didn't work after all.
Later I discovered that phpsession is actually based on cookies, so to set the session life cycle, you must first set the cookie expiration time. Because when the client (such as a browser) logs in to the website, to determine whether the SESSION is useful, first check whether the client has a COOKIE, and then use the SESSION ID in the COOKIE to find the file on the server.
In this case, the following settings are made:
session_set_cookie_params( 12*60*60);//设置cookie的有效期 session_cache_expire(12*60);//设置session的有效期
The above is the detailed content of How to set the php session life cycle?. For more information, please follow other related articles on the PHP Chinese website!