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

查看:64
本文介绍了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 中,他进行了会话:

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

选项卡2 中,会话为:

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

现在刷新时,我需要在活动选项卡中获取当前会话.例如,如果用户刷新选项卡2,则需要在加载时获取选项卡2的$_SESSION['xxx'],即"ipsum".但是$_SESSION['xxx']不应在选项卡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是基于每个客户端(浏览器)而不是选项卡的.因此,没有简单易行的方法可以做到这一点.有多种方法可以通过创建自己的会话处理程序来实现,但是它们比解决方案更多的是hack,因此具有自身的风险和复杂性.无论出于何种原因,我都可以肯定有比会话拆分更好的体系结构解决方案.

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天全站免登陆