What is the time-out of the session in PHP?

Source: Internet
Author: User
Novice beginner PHP, many do not know where to ask for advice. Previously learned ASP, know that there is a session.timeout can set the timeout time, the default is 20 minutes. However, PHP does not find a similar set session timeout function, I do not know if the PHP page is not refreshed that the server side without any request for the default time of the session will expire?

In php.ini there is a session.cookie_lifetime default is 0, this 0 and session timeout is related? 0 is not the representative as long as the browser does not close, the session has been valid, does not time out?
In addition, the configuration file also has a session.gc_maxlifetime = 1440, this check manual is garbage collection delete the default TMP directory Sess file time-out, the default 1440 seconds is 24 minutes is the session timeout time? After 24 minutes, the Sess file is likely to be deleted, which means that the session also fails? But this deletion has a probability, the default of 1/1000, which is very large may not be deleted, if not deleted session has been effective will not time out? That is, 24 minutes without a refresh session will not necessarily expire?

Solving.


Reply to discussion (solution)

Session.gc_maxlifetime is not for the duration of the session, but for the garbage collection process GC
He informs the GC process that it is possible to delete temporary files that were modified before session.gc_maxlifetime seconds

Of course, as long as the SessionID corresponding temporary file exists, the session will be valid

To control the behavior of the session autonomously, you need to write your own processing code. The manual or the sample code on the Web just demonstrates the basics, and you need to scale it to your needs

The time-out period of the session is not very accurate.
If required, the expiration time is recorded in the session, when the session file does not exist, or there is an expiration time-out, when it fails.

if (isset ($_session[' name ')) {    if ($_session[' name '] [' expire ']>time ()) {       echo ' SESSION not expired ';   } else{       Echo ' session not expired ';   }} else{    Echo ' Session expired ';}

Thanks, I got a rough idea.
Upstairs.
if ($_session[' name '] [' expire ']>time ()) {
Echo ' Session not expired ';
}
It should be the echo ' session has expired '; It

There is no definite default session timeout in PHP, if you want to control the user session timeout, you need to control your own programming

if ($_session[' name '] [' expire ']>time ()) {
Echo ' Session not expired ';
}

The period??? than in the small-time, ah, than the big??? Period?
Tomorrow, today?? What is the period? No, it's not.

Well, understanding is wrong, according to the above understanding, then
if ($_session[' name '] [' expire ']>time ()) {
Echo ' Session not expired ';
}else{
Echo ' Session not expired ';
}
In
else{
Echo ' Session has not expired '; Should-----be changed to 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.