PHP - 每个选项卡的会话 [英] PHP - Session per Tab

查看:24
本文介绍了PHP - 每个选项卡的会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为每个浏览器选项卡创建会话?

Is it possible to make sessions per Browser tabs?

例如,用户在浏览器中打开了 2 个标签:标签 1标签 2

As example a user opened 2 tabs in his browser: Tab 1 and Tab 2

标签 1 中,他有一个会话:

In Tab 1 he has a session:

$_SESSION['xxx'] = 'lorem';

标签 2 中,会话是:

$_SESSION['xxx'] = 'ipsum';

现在刷新我需要在活动选项卡中获取当前会话.例如,如果用户刷新选项卡 2,我需要在加载时获取选项卡 2 的 $_SESSION['xxx'],即ipsum".但是 $_SESSION['xxx'] 不应在 Tab 1 上更改.

Now on refresh i need to get the current session in the active tab. For example if the user refreshes Tab 2 i need to get the $_SESSION['xxx'] for tab 2 on load which is 'ipsum'. But $_SESSION['xxx'] shouldn't change on Tab 1.

是否有任何选项可以保存每个标签的会话.如果不是,还有什么其他选择可以处理这个问题?

Is there any option to save sessions per tab. If not what are other options to handle this issue?

感谢您的帮助!

推荐答案

PHP 将会话 ID 存储在 cookie 中,cookie 是针对每个客户端(浏览器),而不是选项卡的.所以没有简单易行的方法来做到这一点.有一些方法可以通过创建自己的会话处理程序来做到这一点,但它们比解决方案更具有攻击性,因此具有其自身的风险和复杂性.无论出于何种原因您可能需要它,我很确定有比会话拆分更好的架构解决方案.

PHP stores session IDs in cookies and cookies are per client (browser), not tab. So there is no simple and easy way to do this. There are ways of doing this by creating your own session handlers, but they are more hacks than solutions and as such come with their own risks and complexity. For whatever reason you may need this, I am quite sure that there is a better architectural solution than session splitting.

这篇关于PHP - 每个选项卡的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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