Can anyone please suggest a best method in PHP to make a user logs-in from only one machine at a time.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Set a key in your session that you store in the database in the user table:
Table User
On Login:
On every page:
This makes sure that a login expires automatically if there is a newer login. There can be only one logged in user per account at any time.
UPDATE
Just saw your comment to the Question. My answer does not work for you as it doesn’t disallow a second login but instead invalidates any previous login.
If you want to prevent a second login then using a timestamp that you update on every page is the best solution:
On login:
(Assuming MySQL:)
If a row was found then the account exists and the login is not blocked by another login.
You might want to split that into two queries (first check login, then check last access) to give a better error message for failed logins, otherwise it’s either “account does not exist” or “blocked”.
On every page: