Jump to content

How to check if already logged in


elabuwa

Recommended Posts

Hi guys,

 

Have a wierd scenario where my brain is simply refusing to think.  :wtf: :wtf: :shrug: :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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.