Deny multiple logins with the same credentials in php

My site has premium videos that users have to pay for in order to watch it. I send a random username and password to the user's email id when the payment is completed. Then I want to ensure that more than one user uses these credentials at the same time. To do this, I use the login_status column in the database table with login credentials and change it to 1 when one user logs in and changes the value to 0 when the user logs off. But the problem is that if the user can close the browser or lose the network connection, this will not lead to an update of the database. Then login_status will be 1 indefinite and no one will be able to use these credentials again.

Is there an idea to complete my task?

+3
source share
3 answers

How about you writing the timestamp to the database when the user logs in. Perhaps you have some logic for periodically updating this value if the user is still registered - for example, a page might make an AJAX request to update the value every 5 minutes or something else.

Then, if the value is greater than a certain threshold (say, 1 hour), you can allow re-entry into the system - which, of course, will reset the time stamp and will not allow anyone else to access.

+3
source

Try creating your own session handler. The right place to store data is next to the session information - and you get the benefits of fully automatic garbage collection.

cookie ( ) - , , .

.

+1

Periodically (hourly?) Scan the database and change all login_statuses parameters to 0.

Change it to 1 when the user uses the site for any reason.

Thus, no one will be blocked for more than 1 hour at a time.

0
source

Source: https://habr.com/ru/post/1748172/


All Articles