How to set and use the validity period of php session

PHPz
Release: 2023-03-05 22:38:02
Original
2370 people have browsed it

php Session validity period setting and usage method: 1. Set the validity period and opening of the session, the code is [ini_set(session.cookie_lifetime...)]; 2. Open the session, and then get the corresponding session.

How to set and use the validity period of php session

[Related learning recommendations:php graphic tutorial]

How to set and use the php session validity period:

Method 1: Set the validity period of the session and open it

function actionLogin(){ ini_set('session.gc_maxlifetime', "60"); // 设置为和“session.cookie_lifetime”一样的时间;(个人理解:设定session有效期) ini_set("session.cookie_lifetime","60"); //这个代表SessionID在客户端Cookie储存的时间,默认是0,代表浏览器一关闭SessionID就作废……就是因为这个所以Session不能永久使用! session_start(); $_SESSION['access_token']='c262e61cd13ad99fc650e6908c7e5e65b63d2f32185ecfed6b801ee3fbdd5c8b'; echo @$_SESSION['access_token']; exit; }
Copy after login

Method 2: If you want to retrieve the session saved above, first open the session, and then retrieve the corresponding session

function actionStest(){ session_start(); echo @$_SESSION['access_token'];exit; }
Copy after login

The effect of F12 is as follows

How to set and use the validity period of php session

Related learning recommendations:php programming(video)

The above is the detailed content of How to set and use the validity period of php session. 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!