Home >Backend Development >PHP Tutorial >Introduction to PHP5 Session life cycle_PHP tutorial

Introduction to PHP5 Session life cycle_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:40:11907browse

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();
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321407.htmlTechArticleIt is judged by Session ID. What is Session ID is the file name of the Session file, Session ID It is randomly generated, so it can guarantee uniqueness and randomness, ensuring...
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