Ask questions about session timeout in php

Source: Internet
Author: User
Could you tell me the timeout time of the session in php? This post was last edited by webstaryoyo from 2014-07-1312: 36: 20 for beginners of php, and I am not familiar with this post. 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. & Nbsp; however, PHP does not find a session timeout value similar to the session timeout value. Is there a session timeout value in php?

This post was last edited by webstaryoyo at 12:36:20

For beginners who are new to php, I am not familiar with many things. 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?

.
------ 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.
------ Solution --------------------
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 not expired ';
}
} Else {
Echo 'session expired ';
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.