dousui7410 2013-03-25 09:38
浏览 63

PHP:关闭浏览器后继续获取旧的会话ID

I have set up a PHP5 script which uses sessions. Starting the session goes wel, and it also creates a cookie (as expected).

However after closing the browser (Firefox 19.0.2 on Mac OSX Mountain Lion) and opening the browser the session ID stays the same. Even after a couple of days. This however while the session.cookie_lifetime is set to 0

In PHP I use this to start the session:

//set cookie params: lifetime, path, domain, https, http-only
session_set_cookie_params(0, "/", null, false, true);

session_name('MySession');

//start session
session_start();

Here is my PHP.ini

session.use_cookies = 1
session.use_only_cookies = 1
session.cookie_httponly = 1
session.cookie_lifetime = 0
session.cookie_path = /
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.hash_function = 1
session.hash_bits_per_character = 6
session.save_path = /var/lib/php5
session.name = PHPSESSID

The session files do net get removed in the /var/lib/php5 After a session_destroy() the files will be removed.

However, after using the script again (starting a session) I will get the old session ID. Last friday I logged out from my computer and now I am back I still get this old session ID. I would really like to have a new session ID after closing the browser (command Q)

I just read about a naggy 'feature' of firefox which stores the cookie for you as if you never closed the browser.

Firefox session cookies

I think this might just be the reason why. As I don't want this I need to find a work-around.

Can you advise me about this?

  • 写回答

1条回答 默认 最新

  • doww38701 2013-03-25 09:46
    关注

    You have to set the cookie life time in the function other wise it will remains there. You have to provide some expire time there. Here are some examples contributed http://php.net/manual/en/function.session-set-cookie-params.php

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值