Home >Backend Development >PHP Problem >How to prevent users from logging in at the same time in php

How to prevent users from logging in at the same time in php

藏色散人
藏色散人Original
2021-03-31 10:08:433169browse

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

How to prevent users from logging in at the same time in php

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.

How to prevent users from logging in at the same time in php

【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!

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