PHP How to do a member account can not be logged in two places at the same time

Source: Internet
Author: User
If Wang in a to land the account, and Xiao Chen in the B also landed in the account, then a to the small Wang computer pop up a hint: Your account has been landed elsewhere, and then the account of the small King landing automatically pushed offline.
In what way?


Reply to discussion (solution)

Log in??? Log in??? Log in IP, the root IP award?
If you log in to the ground?? The last time you log in to the ground, and the accesses into?? In a certain???, the department of information? Tips for the last login?

Each time through the login form of the site, after successful login, the database user table in the user data, update a new key (according to some conditions randomly generated strings), and hit the cookie.

All pages in the site, check each refresh: The value of the cookie and the value of the key in the database table, do a comparison. Unequal, clear cookies, kick out.

This can only be judged by IP.

Now that you are logged in, check the user table
Add a field to the user table to store the login status

Check the login status while checking the legality of the user. If you are logged in, you are not allowed to log in

If the logged-on user does not exit voluntarily, and then is forced to reset by the administrator if necessary

Using the database to manage the session itself, there is a user ID field. If you have the same ID in the library after logging in, you are repeatedly logged in. Delete which session, which user is offline.

Whether this is an online field in the User table, check this field when logging in

To determine the login status is logged in the state is changed to 1 this time when the login will be two 1 there is a conflict can be achieved only login (blind)

You can generate a unique string at login, such as the current timestamp record to the database, but also recorded in the session, each time the page operation, determine whether the user is logged in, but also judge the string, not the same as prompted to log in elsewhere.

  • 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.