cloudll Posted March 2, 2012 Share Posted March 2, 2012 When a user logs in to my members area, their online status is set to 2 in my database and they are displayed as online for everyone else to see. And when they click log out their online status is set to 1 and they are no longer shown as online. My problem is when the session expires due to inactivity, the database isnt updated and they are still shown as online. So whenever the access a page in the members area I have made it so that time also gets entered into the database. And my goal is to have the users online page auto refresh every 5 minutes to check the current time against the time stored in the database for that user and if 15 minutes has past, have the online status in the database updated to 1 again. im using pdo but im a novice at it and havnt been able to find much help on google. Is there a way i can use an if statement to check the two times and only update the online field to 1 for the inactive users while leaving the users who appear active as 2? Sorry if this was confusing, i wasnt too sure how to word it properly. Quote Link to comment https://forums.phpfreaks.com/topic/258109-updating-database-when-users-appear-inactive/ Share on other sites More sharing options...
requinix Posted March 2, 2012 Share Posted March 2, 2012 Don't use that method. There's a much simpler way: Unless your "online" field does more than just indicate online versus offline, remove it. Instead store a timestamp of the last action taken; update it when they do something (like load a page). Then your online count is simply the number of users whose timestamp is more than 15 minutes ago. Quote Link to comment https://forums.phpfreaks.com/topic/258109-updating-database-when-users-appear-inactive/#findComment-1323105 Share on other sites More sharing options...
cloudll Posted March 2, 2012 Author Share Posted March 2, 2012 Im not sure if that will work for what i need. The members area is working in conjunction with a game that displays the users little character on a game field so its not just the users online page. Quote Link to comment https://forums.phpfreaks.com/topic/258109-updating-database-when-users-appear-inactive/#findComment-1323109 Share on other sites More sharing options...
requinix Posted March 2, 2012 Share Posted March 2, 2012 Then use a view which has an IF in it, doing the same logic as your code does (which it actually wouldn't have to do if you used the view). IF((lastaction + INTERVAL 15 MINUTE) Quote Link to comment https://forums.phpfreaks.com/topic/258109-updating-database-when-users-appear-inactive/#findComment-1323111 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.