Home > Backend Development > PHP Tutorial > A strict PHP Session session timeout setting method_PHP tutorial

A strict PHP Session session timeout setting method_PHP tutorial

WBOY
Release: 2016-07-13 10:28:35
Original
838 people have browsed it

Recently, a PHP project used the function of limiting the login time. For example, if the user logs into the system for 60 minutes and there is no operation, it will automatically log out. I searched the Internet and collected the following methods for reference.

The first method is to set the php.ini configuration file and set the session.gc_maxlifetime and session.cookie_lifetime node attribute values. Of course, you can also use the ini_set function to change the attribute values ​​​​of the current context:

Copy code The code is as follows:

ini_set('session.gc_maxlifetime', "3600"); // Seconds
ini_set("session.cookie_lifetime", "3600"); // Seconds


The second method is to set the Session timestamp, such as the following method.

When the login is successful, set the timestamp to 1 hour later than the current time, $_SESSION['expiretime'] = time() + 3600;. Use the following code to check user login status:
Copy code The code is as follows:

if(isset($_SESSION['expiretime '])) {
if($_SESSION['expiretime'] < time()) {
unset($_SESSION['expiretime']);
header('Location: logout.php? TIMEOUT'); // Log out
                                                                                                                                                                                                           >}

According to laruence’s article "How to set up a Session with a strict 30-minute expiration", we can combine the first and second methods to finally determine the session timeout.


http://www.bkjia.com/PHPjc/781415.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/781415.htmlTechArticleRecently, a PHP project used the function of limiting the login time. For example, if the user logs in to the system for 60 minutes and there is no operation, Automatically exit. I searched the Internet and found the following methods for reference...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template