Modification requirements: after an account is logged on, other users can log on to the account again! The current account will be forced to go offline, just like abnormal qq login! What are their specific implementation ideas ?? Modification requirements: after an account is logged on, other users can log on to the account again! The current account will be forced to go offline, just like abnormal qq login! What are their specific implementation ideas ??
Reply content:
Modification requirements: after an account is logged on, other users can log on to the account again! The current account will be forced to go offline, just like abnormal qq login! What are their specific implementation ideas ??
Generate a token that exists in the database and write it to the session. During the operation, compare the session token with the database. logout is different.
"Other users can log on to this account again! The current account will be forcibly deprecated"
Here you need to be timely, or refresh (send an http request again.
The former requires a persistent connection similar to socket, or uses a Heartbeat packet.
Next or the latter operation, @ xfspace also makes it clear.
A random token is generated for each login to verify the cookie.
The tokens generated by different logins are also different. Naturally, the previously generated cookies will become invalid.
However, it should be noted that if the user directly copies the cookie and injects it into the browser of another computer in the Lan, it is hard to identify the server.
How can this problem be solved.
1. create a token table.
Field: token (token, generally 8 random strings), uid (user ID on this site), expiresIn (Expiration Time)
When a user logs on successfully, insert a record and delete all the previous tokens of the user. This ensures that only one valid token works at a time, it does not allow repeated logon.