Home>Article>Backend Development> How to set session validity period in php
How to set the session validity period in php: You can set the session life cycle by setting session.gc_maxlifetime. session.gc_maxlifetime refers to setting the maximum expiration time of the session.
In PHP, the life cycle of the Session is mainly set by setting session.gc_maxlifetime.
(Recommended tutorial:php graphic tutorial)
session.gc_maxlifetime refers to setting the maximum expiration time of the session, which means that PHP will perform its garbage collection according to a certain probability Mechanism, this mechanism refers to judging whether the current time minus the last modification time of the session file is greater than session.gc_maxlifetime, and if so, delete the session file.
Code example:
(Video tutorial recommendation:php video tutorial)
An encapsulated function is provided below for reference only.
The code is as follows:
The above is the detailed content of How to set session validity period in php. For more information, please follow other related articles on the PHP Chinese website!