Home  >  Article  >  Backend Development  >  如何改变Session生命周期?

如何改变Session生命周期?

WBOY
WBOYOriginal
2016-06-23 13:14:29807browse

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

  • 第一种

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

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

Thanks ~

深度解析 Session 机制

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