If the page does not operate for a long time, how to let the session automatically exit

Source: Internet
Author: User
Ask: If the page does not operate for a long time, how to let the session automatically exit.


Reply to discussion (solution)

Impossible, because PHP will not actively work
But you can put the current time in the session as the next entry to determine whether to timeout the basis

The session is destroyed in only two cases: first: The session invokes the Session.invalidate () method. Second: The previous two requests exceeded the lifecycle time specified by the session. Default 30 minutes, if more than 30 minutes are automatically emptied. This value can be set.

The session is destroyed in only two cases: first: The session invokes the Session.invalidate () method. Second: The previous two requests exceeded the lifecycle time specified by the session. Default 30 minutes, if more than 30 minutes are automatically emptied. This value can be set.

Can ask again, how to set the value of this period. Thanks


The session is destroyed in only two cases: first: The session invokes the Session.invalidate () method. Second: The previous two requests exceeded the lifecycle time specified by the session. Default 30 minutes, if more than 30 minutes are automatically emptied. This value can be set.

Can ask again, how to set the value of this period. Thanks
This thing will depend on JS to work. For example, each page header is put a JS logo. As to how to achieve. Everyone has their own ideas, then timer Ajax to request PHP, and then PHP would like to do all the ha.

Setting the session life cycle can be set in php.ini

More flexible way to do??
Session general file, database, cookie several ways
The first two can be based on the time control of PHP Delete session related files or records, the latter can control the cookie
But the trigger way, because it is a long time no operation, so self-triggering is difficult, to third-party trigger

Reference
The Sessionhandler class
(PHP 5 >= 5.4.0)

The Sessionhandlerinterface class
(PHP 5 >= 5.4.0)


The session is destroyed in only two cases: first: The session invokes the Session.invalidate () method. Second: The previous two requests exceeded the lifecycle time specified by the session. Default 30 minutes, if more than 30 minutes are automatically emptied. This value can be set.

Can ask again, how to set the value of this period. Thanks

The Session.gc_maxlifetime in php.ini.

Sets the length of time for the session.

Setting the session life cycle can be set in php.ini

More flexible way to do??
Session general file, database, cookie several ways
The first two can be based on the time control of PHP Delete session related files or records, the latter can control the cookie
But the trigger way, because it is a long time no operation, so self-triggering is difficult, to third-party trigger

Reference
The Sessionhandler class
(PHP 5 >= 5.4.0)

The Sessionhandlerinterface class
(PHP 5 >= 5.4.0)
The last two references are the ultimate solution. and can block the session expiration processing details, the business logic does not need to consider the session expiration situation.

  • Related Article

    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.