If the page is not operated for a long time, how to automatically exit the session-php Tutorial

Source: Internet
Author: User
If the page is not operated for a long time, how to automatically exit the session? Tutorial: if the page is not operated for a long time, how to automatically exit the session. if the sessionphp page is not operated for a long time, how can I automatically exit the session?
Tutorial: if the page is not operated for a long time, how can I automatically exit the session.

Session php

Share:


------ Solution --------------------
Impossible, because php won't take the initiative to work
However, you can put the current time in the session as the basis for judging whether the time has timed out at the next entry.
------ Solution --------------------
There are only two scenarios for Session destruction: first, session is called. invalidate () method. second, the first and second requests exceed the lifecycle specified by the session. the default value is 30 minutes. if it exceeds 30 minutes, it is automatically cleared. This value can be set.

------ Solution --------------------
Reference:
Quote: reference:

There are only two scenarios for Session destruction: first, session is called. invalidate () method. second, the first and second requests exceed the lifecycle specified by the session. the default value is 30 minutes. if it exceeds 30 minutes, it is automatically cleared. This value can be set.


You can ask how to set the value of this period. Thank you

This is something that relies on js to work. For example, each page header has a js ID. As for how to implement it. Everyone has their own ideas, and then the timer ajax requests php, and then php can do everything they want ..
------ Solution --------------------
You can set the session lifecycle in php. ini.

More flexible options ――
Session files, databases, and cookies
The first two types can be used to delete session-related files or records based on time control through php, and the last one can control the cookie
But the trigger method? because there is no operation for a long time, it is difficult to trigger it by a third party.

Reference
The SessionHandler class
(PHP 5> = 5.4.0)

The SessionHandlerInterface class
(PHP 5> = 5.4.0)


------ Solution --------------------
Reference:
Quote: reference:

There are only two scenarios for Session destruction: first, session is called. invalidate () method. second, the first and second requests exceed the lifecycle specified by the session. the default value is 30 minutes. if it exceeds 30 minutes, it is automatically cleared. This value can be set.


You can ask how to set the value of this period. Thank you


Session. gc_maxlifetime in php. ini
------ Solution --------------------
Set the session length.
------ Solution --------------------
Reference:
You can set the session lifecycle in php. ini.

More flexible options ――
Session files, databases, and cookies
The first two types can be used to delete session-related files or records based on time control through php, and the last one can control the cookie
But the trigger method? because there is no operation for a long time, it is difficult to trigger it by a third party.

Reference
The SessionHandler class
(PHP 5> = 5.4.0)

The SessionHandlerInterface class
(PHP 5> = 5.4.0)

The last two references are the ultimate solutions. The service logic does not need to consider session expiration.

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.