Home  >  Article  >  Backend Development  >  How to set session timeout expiration time in php

How to set session timeout expiration time in php

王林
王林Original
2020-07-17 16:04:393709browse

The method for php to set the session timeout expiration time is: it can be achieved through the ini_set() function. This function is used to set the value of php.ini, which takes effect when the function is executed. The specific code is: [ini_set('session.gc_maxlifetime', "3600")].

How to set session timeout expiration time in php

To set the session timeout expiration time, you can use the ini_set() function.

(Recommended tutorial: php tutorial)

Function introduction:

PHP ini_set is used to set the value of php.ini when the function is executed It takes effect. After the script ends, the setting becomes invalid. You can modify the configuration without opening the php.ini file, which is very convenient for virtual spaces.

Syntax:

string ini_set(string $varname, string $newvalue)

Code implementation:

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

You can also edit the php.ini configuration file and set session.gc_maxlifetime and session. cookie_lifetimeNode attribute value, so you can also set the timeout expiration time.

Related topic recommendations: php session (including pictures, texts, videos, cases)

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

Statement:
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