Home  >  Article  >  Backend Development  >  Just like 12306 logs in on the computer but logs out on the mobile phone. How is this situation achieved?

Just like 12306 logs in on the computer but logs out on the mobile phone. How is this situation achieved?

WBOY
WBOYOriginal
2016-08-04 09:20:572193browse

Use database control to save user status id, so that you can only log in on one machine

What I mean by single sign-on here is to log in in one place, and you don’t need to log in to other systems

Just like 12306 logged in on the computer and logged out on the mobile phone.

Reply content:

Use database control to save user status id, so that you can only log in on one machine

What I mean by single sign-on here is to log in in one place, and you don’t need to log in to other systems

Just like 12306 logged in on the computer and logged out on the mobile phone.

Thank you for the invitation. Unique login restriction. Each time the user logs in, it is set to generate a unique ID or token. It is best to limit it by time and always keep it up-to-date and valid.

The login operation generates a login token and saves it in the database and deletes the old token data. This ensures that there is only one Client login account. If the login token is invalid, let it log out

According to session_id, record the latest session_id, the old one is invalid

The idea is to use unique login restrictions and message push to achieve real-time logout. If I do it, I will save a copy of the temporary token in memcache and a copy of the local website. When logging in from a new location, I will update the token on memcache and check whether the local token of the website is consistent with the one in memcache. If it is inconsistent, It's the old login point, and then just delete it.

You didn’t ask clearly
Do you want to log out when the pc is logged into the mobile phone, and log out when the mobile phone is logged into the pc. Or, once you log in on the PC, you will log out when the mobile phone performs the next operation. Once you log in on the mobile phone, you will log out when the PC performs the next session. Of the two, one is active and the other is passive. If it is active, then the answer above can be used. If it is passive:
The mobile terminal can establish a service for background service
The PC terminal can use socket communication. Or it can be completed by ajax scheduled request

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn