jbooth952 Posted November 8, 2008 Share Posted November 8, 2008 What is the general design technique used to keep track of who is logged in, etc, like what is at the bottom of this forum's home page? How do you do that? Just need a general overview. Where is the info stored and accessed? Link to comment https://forums.phpfreaks.com/topic/131954-users-logged-in-etc-design/ Share on other sites More sharing options...
php.ajax.coder Posted November 8, 2008 Share Posted November 8, 2008 use php sessions Link to comment https://forums.phpfreaks.com/topic/131954-users-logged-in-etc-design/#findComment-685626 Share on other sites More sharing options...
Garethp Posted November 8, 2008 Share Posted November 8, 2008 Generally you would have at the top of each page update when the user was online, setting it to time(); Then at the bottom you'd have $SetOn = 24; $SetOn *= 1000; $SetOn = time() - $SetOn; mysql_query("SELECT * FROM users WHERE Online > '$SetOn'"); or something like that Link to comment https://forums.phpfreaks.com/topic/131954-users-logged-in-etc-design/#findComment-685631 Share on other sites More sharing options...
jbooth952 Posted November 8, 2008 Author Share Posted November 8, 2008 use php sessions I do use sessions, but how do you know when a user logs off if he doesn't use your logout, but instead simply closes the browser? Link to comment https://forums.phpfreaks.com/topic/131954-users-logged-in-etc-design/#findComment-685648 Share on other sites More sharing options...
jbooth952 Posted November 8, 2008 Author Share Posted November 8, 2008 I understand the concept of flagging the user record when he logs on, and doing a query of all users logged on, but how do you know when a user logs off if he doesn't use your logout, but instead simply closes the browser? Generally you would have at the top of each page update when the user was online, setting it to time(); Then at the bottom you'd have $SetOn = 24; $SetOn *= 1000; $SetOn = time() - $SetOn; mysql_query("SELECT * FROM users WHERE Online > '$SetOn'"); or something like that Link to comment https://forums.phpfreaks.com/topic/131954-users-logged-in-etc-design/#findComment-685651 Share on other sites More sharing options...
runnerjp Posted November 8, 2008 Share Posted November 8, 2008 well what you have to do really is set a time frame... if u look on here it says within the last 15 minutes... se somethign like <?php $getusersonline = "SELECT user_id,user FROM useronline WHERE timestamp > " . (time() - 900); //grab from sql users on in last 15 minutes $getusersonline2 = mysql_query($getusersonline) or die("Could not get users"); $num = mysql_num_rows($getusersonline2); echo "<b>There " . ($num != 1 ? "are" : "is") . " $num user" . ($num != 1 ? "s" : "") . " currently viewing the forums. </B>"; $tmp = array(); while ($getusersonline3 = mysql_fetch_array($getusersonline2)) { $tmp[] = "<A href='$getusersonline3[user]'>$getusersonline3[user]</a>"; } echo implode(',', $tmp); Link to comment https://forums.phpfreaks.com/topic/131954-users-logged-in-etc-design/#findComment-685674 Share on other sites More sharing options...
sKunKbad Posted November 8, 2008 Share Posted November 8, 2008 I do use sessions, but how do you know when a user logs off if he doesn't use your logout, but instead simply closes the browser? You don't. If you use a session, then when the user closes their browser, the session cookie is deleted. The cookie will usually hold the user's ID, and a token of some sort. It is common to use a timestamp that is salted and then encrypted for this token. You could also add or use an encrypted user agent string for a token. If you want a good login class or a way to authenticate users, you should search the internet for "php session hijacking", and "php session fixation". You will find a lot of examples of login scripts that do their best to defeat hackers. Link to comment https://forums.phpfreaks.com/topic/131954-users-logged-in-etc-design/#findComment-685704 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.