How to set session expiration in PHP

Release: 2023-04-08 12:58:01
forward
2676 people have browsed it

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
Copy after login

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!

Related labels:
php
source:csdn.net
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!