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.
[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; }
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; }
The effect of F12 is as follows
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!