如何改变Session生命周期?

WBOY
Release: 2016-06-23 13:14:29
Original
806 people have browsed it

在浏览器启用 Cookie 的情况下,设置 Cookie 中 Session ID 的有效时间进行实现。

  • 第一种

    session_start();$_SESSION['name'] = 'Bihu';$life_time=60; //保存1分钟setcookie(session_name(),  session_id(),  time()+$life_time, "/");
    Copy after login
  • 第二种

    session_start();$_SESSION['name'] = 'Bihu';$life_time=60; //保存1分钟session_set_cookie_params($life_time);session_regenerate_id(true);
    Copy after login
    //session_regenerate_id() //bool session_regenerate_id ([ bool $delete_old_session = false ])//在不修改当前会话中数据的前提下使用新的 ID 替换原有会话 ID。//详情,可见PHP手册。
    Copy after login

Thanks ~

深度解析 Session 机制

source:php.cn
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!