LooieENG Posted May 15, 2008 Share Posted May 15, 2008 I don't have a clue how to go about doing this, any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/105679-solved-suggestions-for-displaying-whether-a-user-is-onlineoffline/ Share on other sites More sharing options...
btherl Posted May 15, 2008 Share Posted May 15, 2008 Are you using mysql? A brief description of your app would be nice too, otherwise we may give totally unrelated advice! Quote Link to comment https://forums.phpfreaks.com/topic/105679-solved-suggestions-for-displaying-whether-a-user-is-onlineoffline/#findComment-541451 Share on other sites More sharing options...
MadTechie Posted May 15, 2008 Share Posted May 15, 2008 *i already typed this while btherl posted so this maybe unrelated advice Create a table, when the user logs in you insert a records, and update its timestamp when they perform actions, for the whos online you check the database for records with a timestamp no later than erm.. 15 minutes.. make sense Quote Link to comment https://forums.phpfreaks.com/topic/105679-solved-suggestions-for-displaying-whether-a-user-is-onlineoffline/#findComment-541454 Share on other sites More sharing options...
StormTheGates Posted May 15, 2008 Share Posted May 15, 2008 With MYSQL I would have a cell called lastaction and then everytime they click have it update to the current time. Then when you want to show them as online or offline have it compare the lastaction time to like time()-600 for within 10mins. Quote Link to comment https://forums.phpfreaks.com/topic/105679-solved-suggestions-for-displaying-whether-a-user-is-onlineoffline/#findComment-541455 Share on other sites More sharing options...
LooieENG Posted May 15, 2008 Author Share Posted May 15, 2008 Well, I'm trying to make a forum, and I have an idea for how I can make everything work (adding threads, posts, etc.) but I'm not sure how to set a user's status to online/offline. PHP 5.2.5 and MySQL 5.0.45 Edit: Ah, yeah. I should've thought of that . Thanks everyone. Quote Link to comment https://forums.phpfreaks.com/topic/105679-solved-suggestions-for-displaying-whether-a-user-is-onlineoffline/#findComment-541456 Share on other sites More sharing options...
StormTheGates Posted May 15, 2008 Share Posted May 15, 2008 Whenever a user clicks $time = time(); mysql_query("UPDATE users SET lastaction='$time' WHERE username='$username'"); Then when you check to see if they are on or off $s = mysql_query("SELECT lastaction FROM users WHERE username='$username'"); while($r = $mysql_fetch_row($s)){ $last = $r[0]; } $range = time()-600; if($range < $last){ echo "User is online!"; } else { echo "User is offline!"; } Quote Link to comment https://forums.phpfreaks.com/topic/105679-solved-suggestions-for-displaying-whether-a-user-is-onlineoffline/#findComment-541460 Share on other sites More sharing options...
LooieENG Posted May 15, 2008 Author Share Posted May 15, 2008 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/105679-solved-suggestions-for-displaying-whether-a-user-is-onlineoffline/#findComment-541463 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.