php method to prohibit users from logging in at the same time: 1. Write the latest login IP to one of the last_login_ip fields in the user table; 2. When the login is successful, transfer to the index controller or index method; 3. Determine whether the current IP is equal to the IP "last_login_ip".
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
PHP prohibits a single user from logging in to multiple devices at the same time, limiting a single Users log in repeatedly from multiple terminals.
The logic is simple mainly due to three points;
1: When logging in, write the latest login IP to one of the last_login_ip fields in the user table
2: When the login is successful Go to the index controller or index method and first query 2 points inside, 1): Current IP 2): IP
#3 in the last_login_ip stored by the current user in the database field: Then make a judgment to judge the current IP Is it equal to the last_login_ip IP? If not, it means that this account has logged in elsewhere. The logic is very simple, I hope it can help everyone, and the code screenshot is attached below. Hope this helps everyone, thank you.
【Recommended learning: PHP video tutorial】
The above is the detailed content of How to prevent users from logging in at the same time in php. For more information, please follow other related articles on the PHP Chinese website!