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?

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!

 

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.