简体   繁体   中英

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: 在此输入图像描述

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?

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. Upon the page being closed, this sessionID would then be cleared and removed from the static list on the backend. 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. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM