Home  >  Article  >  Backend Development  >  How to set session expiration in PHP

How to set session expiration in PHP

尚
forward
2020-03-07 09:36:572677browse

How to set session expiration in PHP

Due to project needs, some data must be saved in SESSION in PHP, but there is always an expiration that cannot be processed. Here is an introduction to the session expiration settings. If the session expiration is set to be invalid, please see The following solution:

Recommendation: "php training"

In PHP, set php.ini and find session.gc_maxlifetime = 1440 #(PHP5 default 24 minutes)

Here you can set the expiration time at will. But some people say that after setting it, it doesn’t seem to work!

In fact, it’s not that it doesn’t work, but because the system defaults:

session.gc_probability = 1
session.gc_divisor = 1000

garbage collection has a probability, 1/1000 means that only one session will be recycled 1000 times.

As long as your visits are large, you can achieve the recycling effect.

Otherwise you can also set the value of session.gc_divisor,

For example: session .gc_divisor = 1, so that you can clearly see the effect of SESSION expiration.

For more programming-related content, please pay attention to the Programming Tutorial column of the php Chinese website!

The above is the detailed content of How to set session expiration in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete