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 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的