[英]How can you check if a user is logged into the site on one tab but not on another tab from the same browser?
GitHub recently implemented a feature whereby if you're viewing a page as a guest in one tab then log into the site from another tab, in the tab where you are still a guest, it will display the following message: GitHub最近实现了一项功能,如果您在一个选项卡中以一个访客的身份查看某个页面,然后从另一个选项卡登录该站点,在您仍然是访客的选项卡中,它将显示以下消息:
This works the same when the tabs are in an incognito/private window. 当标签位于隐身/私人窗口中时,此功能相同。
Does the site/session variables force the client-side to check for existing cookies? 站点/会话变量是否强制客户端检查现有cookie?
If this is purely out of curiosity, there are ways to easily add this. 如果这纯粹是出于好奇,有办法轻松添加它。 As you mentioned, when the page is opened, it would be checking the saved cookies, finding the saved SessionID and checking it with the backend to see if it is still an active session. 正如您所提到的,当页面打开时,它将检查已保存的Cookie,查找已保存的SessionID并使用后端进行检查以查看它是否仍为活动会话。 Upon the page being closed, this sessionID would then be cleared and removed from the static list on the backend. 在页面关闭后,此会话ID将被清除并从后端的静态列表中删除。 You should be able to fill in the missing gaps from here. 你应该能够从这里填补缺失的空白。
Easiest to manage cookies with PHP, calling it with javascript, if you need an idea of a direction to take. 如果您需要了解方向,可以使用PHP轻松管理cookie,使用javascript调用它。 Good luck! 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.