elabuwa Posted October 21, 2011 Share Posted October 21, 2011 Hi guys, Have a wierd scenario where my brain is simply refusing to think. :wtf: :shrug: I have small script which let's a user log in through a login screen. Thats ok. I can check whether the user is already logged in the same machine through sessions. My requirement is : I need to restrict the same username logging in from multiple computers at any one given time. In other words, a user can not use two machines to login at the same time. Can someone please suggest a method to solve this scenario. Your help is very much appreciated. Cheers Elabuwa Quote Link to comment https://forums.phpfreaks.com/topic/249503-how-to-check-if-already-logged-in/ Share on other sites More sharing options...
Psycho Posted October 21, 2011 Share Posted October 21, 2011 Well, that will be very problematic because you have no way to know when a user has "logged off" on one machine in order to allow them to log in on another machine. You ahve two choices: 1) When a user logs in, save the session ID to the data base and have a field to set their "last access" time. Then do not allow another machine to log in as that user as long as the last access time is less than some time limit. For example, you could set the time limit to 20 minutes. So, if you do not see any activity from a user within that time frame you allow them to log in from another machine for the same account. Then when you update the session ID in the table, the first machine will be considered "logged out" so, using the value in the database, you would kill the first machine' session. 2) Using a similar approach to above you could do the same thing but don't use a time limit. So, whenever an authentication attempt is made, if there is an existing session for that user, you would destroy the session for the first machine before completing the authentication of the second machine. Quote Link to comment https://forums.phpfreaks.com/topic/249503-how-to-check-if-already-logged-in/#findComment-1281040 Share on other sites More sharing options...
elabuwa Posted October 24, 2011 Author Share Posted October 24, 2011 Hi, thank you for your reply, i was considering the first option as well. I have seen this working in Gmail. Well of course they have more collective brain power and bling to spend. Quote Link to comment https://forums.phpfreaks.com/topic/249503-how-to-check-if-already-logged-in/#findComment-1281675 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.