Jump to content

PHP / MySQL Online Status for User Authentication System


wintallo

Recommended Posts

Hey,

 

Right now, I'm working on a user authentication system. My problem is with an "online status" element. So far, I have that when the user logs in, a field in my members MySQL table, called loggedinstatus is set to 1. This means that that certain user is currently logged in. The problem is, is that the only way that loggedinstatus is set to 0 (the user is not logged in) is when the user clicks the logout link. If the user just goes to another website or closes his or her browser, the loggedinstatus is left at 1. How would I get around this problem?

Link to comment
Share on other sites

So I could set a cookie every time a logged in user goes to a page

 

setcookie("loggedin", 1, time()+60*10);

 

But how would this help? Yes, after 10 minutes the cookie would die, but how could I interface this with a database?

I want to use this so that on a user list, people could see which users are online and which are not.

 

I might just be missing something really obvious  ;D

 

Thanks for your time!

 

Link to comment
Share on other sites

if you enter a website a database get's the users id name and date now what can you do with that in a new table.

 

maybe setup a login and logout code try.

 

and yes will help but you need to help also by trying to understand ok mate

 

so with this i would come on?

 

1. setup a new what ? ohh  table within the table i want what columns?

Link to comment
Share on other sites

The best way is to have a field in your db that states "Last action time". Use that in your script that if a user's times is greater than 5 minutes it updates the "loggedin" field to be set to 0. There is no other way to obtain this as it is impossible to tell if a user closes their browser/goes to another site.

 

--FrosT

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.