I would like to ask questions about session timeout in php for beginners to learn about php. I have learned asp before and know that there is a session. timeout. you can set the timeout time. the default value is 20 minutes. However, PHP does not find a function similar to setting the session timeout time. I do not know how long the session will expire by default if the php page is not refreshed, that is, if no request is sent to the server?
In php. ini, there is a session. cookie_lifetime. the default value is 0. is this 0 related to the session timeout time? Does 0 mean that the session will remain valid and will not time out as long as the browser is not closed?
In addition, there is a session in the configuration file. gc_maxlifetime = 1440. This manual indicates the timeout time for garbage collection and deletion of sess files in the default tmp Directory. is the default 1440 seconds, that is, 24 minutes, the session timeout time? After 24 minutes, the sess file may be deleted, which means the session is invalid? But there is a probability of deletion. the default value is 1/1000, that is, it is very likely that the session is not deleted. Will it remain valid if the session is not deleted? That is to say, if a session is not refreshed within 24 minutes, will the timeout not always expire?
.
Reply to discussion (solution)
Session. gc_maxlifetime is not for the session validity period, but for the garbage collection process gc
He informed the gc process that the temporary files modified before session. gc_maxlifetime could be deleted.
Of course, as long as the temporary file corresponding to sessionid exists, the session will be valid
To control session behaviors, you need to write and process the code yourself. The manual or online sample code only demonstrates the basic writing method. you need to expand it according to your needs.
The session timeout is not very accurate.
If this parameter is required, the expiration time is recorded in the session. if the session file does not exist or exists but the expiration time times out, the session fails.
If (isset ($ _ SESSION ['name']) {if ($ _ SESSION ['name'] ['expire ']> time ()) {echo 'session not expired ';} else {echo 'session expired ';}
Thank you for your understanding.
Upstairs
If ($ _ SESSION ['name'] ['expire ']> time ()){
Echo 'session not expired ';
}
It should be echo 'session expired ';
I feel that php does not have a definite default session timeout time. if you want to control the user session timeout time, you need to control it by programming.
If ($ _ SESSION ['name'] ['expire ']> time ()){
Echo 'session not expired ';
}
? Period ?? Ratio? In talent? Period AH, ratio? How is it big ??? Period?
Tomorrow? Today ?? Yes? Period? No? Right.
Oh, wrong understanding. as mentioned above
If ($ _ SESSION ['name'] ['expire ']> time ()){
Echo 'session not expired ';
} Else {
Echo 'session not expired ';
}
Medium
Else {
Echo 'session not expired '; ----- should it be changed to echo 'session expired ';?
}