dongzongzhi6953 2013-11-12 20:31
浏览 10

如何更改此代码,以便在浏览器关闭时会话*未设置*?

Here is some very simple code for sessions

ini_set('session.cookie_lifetime', 0);
session_start();
echo session_id();

var_dump($_SESSION);

$_SESSION["name"]  = "test";

I load the page once.

I then comment out

#$_SESSION["name"]  = "test";

I hit reload and can the $_SESSION variables.

If I completely close the browser and start it up, I expect the $_SESSION variable to be completely empty.

Instead I see that "name" is still part of the $_SESSION variable.

Please alter this code so that it empties the $_SESSION if I close the browser. When I open it again, the $_SESSION variable should be empty.

  • 写回答

1条回答 默认 最新

  • doujiang2641 2013-11-12 20:40
    关注

    Not possible. PHP tracks sessions based on a cookie set in the browser, so if your browser persists cookies across separate launches, then your PHP session will continue as well. You could set your session expiry lower, but that applies to all sessions.

    PHP has absolutely no concept of whether or not your browser has been closed between two requests.

    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了