Home  >  Article  >  Backend Development  >  How to set the php session life cycle?

How to set the php session life cycle?

藏色散人
藏色散人Original
2020-09-01 09:47:462214browse

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()".

How to set the php session life cycle?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn