javascript - When registering, the same user registers multiple times, and multiple pieces of the same data appear in the database. The background has been verified, and the front-end js also limits submission once every two seconds, but multiple pieces of data still appear.
世界只因有你
2017-06-30 09:52:16
When registering, the same user registers multiple times, and multiple pieces of the same data appear in the database. The background has been verified, and the front-end js also limits submission once every two seconds, but multiple pieces of data still appear
The front-end can set the registration button to be clickable when entering the page. When clicking to send a registration request, the registration button is first set to be non-clickable. When the request comes back and the registration fails, the button is set to be clickable.
Use unique index as a restriction in the database
I don’t know whether you use
debouce
orthrottle
to limit submission to two secondsA better approach is to click Register to disable the button, wait for the request to return, and then enable the button in the callback function. Remember to enable the Register button in the callback that reports an error
Backend database fields must also be uniquely indexed
Server-side verification requires uniqueness judgment; disable clicks after clicking on the front-end button, wait for the server to return and unblock clicks, or implement it through timeout
Registration requires unique verification
Database plus username primary key unique verification
Although the solution of disabling buttons on the front end is also necessary, it only prevents ordinary users from clicking multiple times and cannot prevent non-browser 'users'
No matter how many repeated requests the server accepts, it must be processed by the backend
Purpose The same user can only register once, refer to other answers, primary key
Refer to my article How to prevent clients from sending repeated requests in web projects