相同的登录用户分配了不同的会话 ID(在不同的浏览器中) [英] same logged in user assigned different session ids (in different browsers)

查看:26
本文介绍了相同的登录用户分配了不同的会话 ID(在不同的浏览器中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 php 中实现了一个基于 mysql 的会话接口.我刚刚发现,如果我使用浏览器 A(例如 Chrome)登录我的帐户,然后我在另一个浏览器 B(例如 IE)中登录同一个帐户,每个浏览器都会被分配 2 个单独的会话 ID.如何让我再次使用浏览器 B 登录时,保留之前浏览器 A 的活动会话?

I've implemented a mysql-based session interface in php. I just found out that if I log in to my account using browser A (e.g. Chrome), and then I log in to the same account in another browser B (e.g. IE), each browser is assigned 2 separate session ids. How can I make it such that when I log in again using browser B, I retain the active session of the previous browser A?

手头的问题是我在会话中存储了某些信息,并且数据在不同浏览器中的相同用户之间没有同步并且正在造成严重破坏.:S

The issue at hand is that I'm storing certain information in the session and the data not being synchronised between the same users in different browsers and is wrecking havoc. :S

有没有办法做到这一点?

Is there a way to achieve this?

谢谢!

推荐答案

如果您要将会话存储在数据库中,请添加一种机制,通过该机制将 userId 存储为数据库会话记录的一部分,从而创建我喜欢称之为的内容一个语义会话".当用户登录时,检查是否已经存在另一个会话;如果是这样,请使用 session_id() 将新会话固定到旧会话的 ID,这将加入它们(并且应该为所有后续请求更改新会话的 ID).请务必仅在登录步骤期间执行此操作,否则您可能会遇到两个会话试图相互交换"并出现异常竞争条件.

If you're storing the session in the database, add a mechanism whereby the userId is stored as part of your database's session record, creating what I like to call a "semantic session". When the user logs in, check to see if another session already exists; if so, use session_id() to fixate the new session to the old session's ID, which will join them (and should change your new session's ID for all subsequent requests). Be sure to only perform this action during the login step, or you might end up with freaky race conditions of two sessions trying to be each other and "swapping".

这篇关于相同的登录用户分配了不同的会话 ID(在不同的浏览器中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆