In PHP, the Session variable is saved on the server side (saved in file format by default), and the SessionID is saved on the client side in the form of a cookie.
There are two ways to destroy the session:
The first is through the program
session_destory()方法清除所有session unset(session['x'])来清除指定的session['x']。
The second is by closing the browser
关闭后会直接清除所有session。
When cookies are not disabled, the session ID is saved in the cookie.
If you want to change the session life cycle, you can set the validity time of the session ID in the cookie. There are two ways to set the session life cycle:
The first one: setcookie()
$lifetime=60;//保存1分钟 session_start(); setcookie(session_name(),session_id(),time()+$lifetime,"/");
Directly use setcookie to set the life cycle of the session id.
Second: session_set_cookie_params()
$lifetime=60;//保存1分钟 session_set_cookie_params($lifetime); session_start(); session_regenerate_id(true);
session_regenerate_id(); method is used to change the value of the current session_id and retain the value of the array in the session. The parameter defaults to false. If set to true, the value of session_id will be changed and the current session array will be cleared.