Jump to content

Recommended Posts

I am trying to figure out the best way to make sure only one user is logged in to each account on my website. I thought about using database to do this, but then if the user doesn't logout I don't know of a way to automatically (when the browser is closed, or session timeout) the database entry changes to reflect this.

 

My other thought was to do a custom session variable with the user ID in it. Then when someone tries to login and it sees that, that user_id has already been assigned a session it won't allow another login. Is there a way to do this?

Link to comment
https://forums.phpfreaks.com/topic/85697-one-user-logged-in-per-account/
Share on other sites

Have a column in your user's row named "user_online" or something like that.

 

And when processing the login, check if "user_login" == 1 (if the user is already online), if it is, then don't allow the login. If it == 0 (user not online), then allow the login.

 

Then, have an activity timeout (every 15 minutes of inactivity or so), and set user_online to 0 (and log the user out).

 

Get what i'm saying? that would work, and if a login cookie is present, you can set user_online to 1.

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.