Home  >  Article  >  Backend Development  >  How to modify the SESSION validity time in PHP?

How to modify the SESSION validity time in PHP?

Guanhui
GuanhuiOriginal
2020-07-24 10:01:173169browse

How to modify the SESSION validity time in PHP?

How to modify the SESSION validity time in PHP?

1. Set the valid time of SESSION by using the function "setcookie()";

<?php
session_start(); 
// 保存一天 
$lifeTime = 24 * 3600; 
setcookie(session_name(), session_id(), time() + $lifeTime, "/"); 
?>

2. Set by using the "session_set_cookie_params" function;

<?php 
// 保存一天 
$lifeTime = 24 * 3600; 
session_set_cookie_params($lifeTime); 
session_start();
$_SESSION["admin"] = true; 
?>

3 , set in "session_start()".

<?php

session_start([
    &#39;cookie_lifetime&#39; => 60 * 60
]);

Recommended tutorial: "PHP"

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

The above is the detailed content of How to modify the SESSION validity 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