Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent multiple login with same login credentials in php

Tags:

database

php

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?

like image 641
shin Avatar asked Feb 26 '26 15:02

shin


1 Answers

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.

like image 80
Justin Ethier Avatar answered Feb 28 '26 06:02

Justin Ethier