Php strictly controls the expiration time of the session. Php strictly controls the expiration time of the session. I believe you will also encounter one problem: 1. the front-end user will be automatically dropped if he does not know how. 2. after logging out of the background, php strictly controls the expiration time of the session.
After working for a while, I believe you have encountered one problem:
1. the front-end users will be automatically dropped if they do not know how.
2. after logging out at the background, all foreground users are disconnected.
3. I want to control the automatic deprecation of my users in half an hour and find that it is difficult to change the configuration file.
All of the above problems were recently encountered by me. later, I learned through the query that the php session mechanism is controlled by several parameters at the same time. Specifically, I will not write specific parameters, which are a probability, A maximum Expiration Time and a session storage path. in php. in ini, we can see that the default expiration time of the php session is 24 minutes, that is, if we do not have an operation page for 24 minutes, the session will expire, of course, this is an ideal situation. after 24 minutes, php will start a session recovery mechanism, which is used to check whether the change time of the session file in the default storage directory is 24 minutes ago. if so, the session will be deleted. of course, this is also ideal. this is a probability mentioned above. the session recovery mechanism is triggered by probability, that is, even if your session is a file 24 minutes ago, if you trigger the recycle mechanism step, your session is still not expired. this is certainly not what we want. to solve this problem, the third parameter I mentioned above is the session storage path. if you have not enabled php. ini internal session. save_path, the session will not be generated by a file, so in order to effectively control the session, we open it and fill in a path, or use session_save_path ("..... ") function to define the storage path of this session. another important thing is that if the session is stored in our own defined path, the seesion recycle mechanism does not work. so we can only control the expiration time of the session by ourselves.
The following is a session expiration processing class that I write according to my understanding.
SavePath = $ savePath; // Note: this must be written before session_start session_save_path ($ this-> savePath); session_start (); // enable sessionif (! Is_dir ($ this-> savePath) {// The maximum permission is 0777 mkdir ($ this-> savePath) or die ('system error! ') ;}/// Creates a session with three parameters. // $ name-> session name/$ val-> session value // $ time-> Expiration time, the default value is 30 minutes public function setSession ($ name, $ val, $ time = 1800) {$ this-> sessionName = $ name; $ this-> sessionValue = $ val; $ this-> time = $ time; if (! Isset ($ _ SESSION [$ this-> sessionName]) {if (is_array ($ this-> sessionValue )) {foreach ($ this-> sessionValue as $ key => $ val) {$ _ SESSION [$ this-> sessionName] [$ key] = $ val ;}} else {$ _ SESSION [$ this-> sessionName] ['Val '] = $ this-> sessionValue ;} $ _ SESSION [$ this-> sessionName] ["startTime"] = time ();} // this indicates that the session already exists, so we can determine whether it has expired. if it has expired, delete sessionelse if (isset ($ _ SESSION [$ this-> sessionName] ["startTime"]) & time ()-$ _ SESSION [$ This-> sessionName] ['starttime'] >=$ this-> time) {unset ($ _ SESSION [$ this-> sessionName]) ;}}?>
Through this class, we can achieve several goals:
1. we can clearly control the expiration time of the session.
2. corresponding to the second question above, when I used to log out, I usually write session_destroy (); or unset ($ _ SESSION ); as a result, all sessions are cleared. Therefore, after the previous user exits, our session is deleted.
3. the user will not be dropped for no reason, because every step is transparent for us now.
Http://www.bkjia.com/PHPjc/1074128.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1074128.htmlTechArticlephp strictly control the expiration time of the session to work for a period of time, I believe you will also encounter a problem: 1. the front-end user will be automatically dropped if he does not know how. 2. log out of the background and log on...