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

How to set the php session life cycle?

藏色散人
Release: 2023-03-05 14:46:02
Original
2232 people have browsed it

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的有效期
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template