How can I use php to implement simultaneous login for one account without multiple users?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.