Home >Backend Development >PHP Tutorial >Introduction to PHP5 Session life cycle_PHP tutorial
It is judged by the Session ID. What is the Session ID is the file name of the Session file. The Session ID is randomly generated, so it can ensure uniqueness and randomness and ensure the security of the Session. Generally, if the Session life cycle is not set, the Session ID is stored in the memory. After closing the browser, the ID is automatically logged out. After re-requesting the page, a new Session ID is registered.
If the client does not disable cookies, the cookie plays the role of storing the Session ID and Session lifetime when starting the Session session. Let’s manually set the lifetime of the Session:
session_start(); // 保存一天 $lifeTime = 24 * 3600; setcookie(session_name(), session_id(), time() + $lifeTime, "/"); ?> |
In fact, PHP5 Session also provides a function session_set_cookie_params(); to set the lifetime of PHP5 Session. This function must be called before the session_start() function is called:
// 保存一天 $lifeTime = 24 * 3600; session_set_cookie_params($lifeTime); session_start(); ?> |