Why Doesn't Closing A Tab Delete A Session Cookie?

后端 未结 5 1737
野性不改
野性不改 2020-11-29 13:15

I\'m using session-based cookies with my website. To my complete surprise, I noticed if I set a session cookie (not a persistent cookie), close a tab, and then reconnect to

5条回答
  •  迷失自我
    2020-11-29 13:29

    This is by design and trying to change it is a very bad idea. What if a user opens a link in a new tab and closes that? Should the session in the original tab be destroyed? Of course not! This demonstrates why you should not even think about this.

    A session ends when the last browser window closes. If you want something else, you:

    1. do not want sessions;
    2. need to make your own "mini-session" infrastructure;
    3. are probably in for a world of hurt and bugs.

提交回复
热议问题