My website has premium videos, for which users have to pay to watch it. I am sending a random user name and password to the user's email id when the payment is completed. Then I want to assure no more than one user use that login credentials simultaneously. For that I use a login_status column in database table with login credentials and change it to 1 when one user login and change to 0 when user log out. But the problem is, if the user close browser or network connection loss may happened will not update database. Then login_status will be 1 undefinitely and no one can use that login credentials again.
Is there any idea to accomplish my task?
How about you write a timestamp into the database when the user logs in. You might have some logic to periodically update this value if the user is still logged in - for example, the page could make an AJAX request every 5 minutes to update the value or something.
Then, if the value is older than a certain threshold (say, 1 hour) you can allow a duplicate login through - which of course will reset the timestamp and prevent anyone else from accessing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With