Home  >  Article  >  Backend Development  >  How to use PHP to allow only administrators to log in, and if the current administrator account is already logged in, other people will not be allowed to log in.

How to use PHP to allow only administrators to log in, and if the current administrator account is already logged in, other people will not be allowed to log in.

WBOY
WBOYOriginal
2016-10-22 00:14:121091browse

How to use PHP to allow only administrators to log in, and if the current administrator account is logged in, other people will not be allowed to log in! ! Asking for advice

Reply content:

How to use PHP to allow only administrators to log in, and if the current administrator account is logged in, other people will not be allowed to log in! ! Asking for advice

If the login is successful, a record will be immediately inserted into the data table, including login time, reply information expiration time and other information. When the second person logs in, the database will be checked for verification

Two int fields. The first records the login timestamp. The second records the logout timestamp. When logging in, the time must be judged. If the current time is greater than the logout timestamp, it means no one is logged in now. If the person who logged in before has not logged out, then Determine whether the key in the session has expired. If it has expired, the previous user must log in again if he wants to operate again. At this time, another person can also log in. I don’t know if I made it clear

You use an online field to record the current user status

Only administrators are allowed to manage. This is very simple. You only need to set an account information, or just write it directly in the code.

If the previous administrator account of

is already logged in, other people will not be allowed to log in

This should be what I want to say: the same account can only be logged in to one place at the same time, right?

I looked at the solutions given by the two people above: One is to set the validity period, but this cannot solve the problem of "simultaneously" logging in at another place.

The second is to record the logout time. The key question is how to record it?

If you want to ensure real-time, you need to use socket
If it is not so strict, you can use scheduled access.

redis stores the key-value pair of userId:sessionKey. Each request checks whether the sessionId corresponding to the current user ID is consistent with the current session

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