mbrown Posted January 26, 2009 Share Posted January 26, 2009 Can anyone help me decide what the easiest way it is to display who is currently logged in thanks Quote Link to comment https://forums.phpfreaks.com/topic/142430-currently-logged-in/ Share on other sites More sharing options...
dropfaith Posted January 26, 2009 Share Posted January 26, 2009 make a column in your user table that is called logged in and when the user logs make it update that field to true and display all users from usertable where logged in = true Quote Link to comment https://forums.phpfreaks.com/topic/142430-currently-logged-in/#findComment-746256 Share on other sites More sharing options...
mbrown Posted January 26, 2009 Author Share Posted January 26, 2009 i just got up but i will try to get some code before i go to class and see what you guys think thanks Quote Link to comment https://forums.phpfreaks.com/topic/142430-currently-logged-in/#findComment-746501 Share on other sites More sharing options...
mbrown Posted January 26, 2009 Author Share Posted January 26, 2009 this is the actual updating of the field //user logs-in include ("database.php"); UPDATE users SET loggedin="Yes" WHERE username = '$userid'; this is where i want to put it include ("database.php"); $userquery = "SELECT username FROM users WHERE loggedin= 'Yes'"; $query = mysql_fetch_assoc(mysql_query($userquery)); if($query[loggedin] == "Yes") { echo $query[username] . " | "; } on log out include ("database.php"); UPDATE SET loggedin='No' WHERE userid = '$userid'; session_start(); session_end(); Quote Link to comment https://forums.phpfreaks.com/topic/142430-currently-logged-in/#findComment-746527 Share on other sites More sharing options...
revraz Posted January 26, 2009 Share Posted January 26, 2009 The best way to handle this is via a timestamp, and just show users with activity say within the last 10 mins. Quote Link to comment https://forums.phpfreaks.com/topic/142430-currently-logged-in/#findComment-746538 Share on other sites More sharing options...
mbrown Posted January 26, 2009 Author Share Posted January 26, 2009 The best way to handle this is via a timestamp, and just show users with activity say within the last 10 mins. how would i be able to do that? never done anything like that before Quote Link to comment https://forums.phpfreaks.com/topic/142430-currently-logged-in/#findComment-746573 Share on other sites More sharing options...
runnerjp Posted January 26, 2009 Share Posted January 26, 2009 yes u will find that trying to get people to log out from your site via the logout button just wont work.. many pople just close the browser. when a user loggs n use timestamp and add it into the db ... then call all users within the last 10-15 min to be shown! Quote Link to comment https://forums.phpfreaks.com/topic/142430-currently-logged-in/#findComment-746597 Share on other sites More sharing options...
mbrown Posted January 26, 2009 Author Share Posted January 26, 2009 hmm something i have to think about. how the sessions set up i have when the browser is closed the session is closed as well thus the user returning needs to log in. that is how i was taught in a class i took last semester. so the way i did it i think will work. i will though look at your suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/142430-currently-logged-in/#findComment-746623 Share on other sites More sharing options...
runnerjp Posted January 26, 2009 Share Posted January 26, 2009 yes but when the seswion ends your db will not be updated Quote Link to comment https://forums.phpfreaks.com/topic/142430-currently-logged-in/#findComment-746626 Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 hmm something i have to think about. how the sessions set up i have when the browser is closed the session is closed as well thus the user returning needs to log in. that is how i was taught in a class i took last semester. so the way i did it i think will work. i will though look at your suggestions. That is true, when browser is closed so is the session. The question you need to ask yourself, is that ok? Let's say that someone is at a public computer in a library, they leave the computer running with the browser open to your site. They essentially created a loop hole, if after 30 minutes another user comes and sees, they will just use that account if they are not nice. However, you may not care to be honest. Most sites that contain shopping carts etc, timeout after 15-20 minutes for this reason. If you do not have sensitive information used for that user, I would say leaving them in until they close the browser is fine. Quote Link to comment https://forums.phpfreaks.com/topic/142430-currently-logged-in/#findComment-746627 Share on other sites More sharing options...
mbrown Posted January 26, 2009 Author Share Posted January 26, 2009 how can i set the session length? we did not cover that in my class that i remember. i could just have the session expire after 15 minutes correct? that is what you are saying? Quote Link to comment https://forums.phpfreaks.com/topic/142430-currently-logged-in/#findComment-746635 Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 how can i set the session length? we did not cover that in my class that i remember. i could just have the session expire after 15 minutes correct? that is what you are saying? Yes, you can set the session timeout in the php.ini config. If you are using this in the db for the currently logged, however, you want that DB entry to expire also like runnerjp said. So, what you do, is create a CRON job or Scheduled Task and run it every 5-10 minutes checking db values. If there is a DB value of lastseen that is more than 15 minutes long you can expire that user in the DB entry. This will not kill their session, without the session timeout. But this will show them as offline if after 15 minutes of inactivity. Hope that makes sense. Quote Link to comment https://forums.phpfreaks.com/topic/142430-currently-logged-in/#findComment-746643 Share on other sites More sharing options...
mbrown Posted January 26, 2009 Author Share Posted January 26, 2009 how can i set the session length? we did not cover that in my class that i remember. i could just have the session expire after 15 minutes correct? that is what you are saying? Yes, you can set the session timeout in the php.ini config. If you are using this in the db for the currently logged, however, you want that DB entry to expire also like runnerjp said. So, what you do, is create a CRON job or Scheduled Task and run it every 5-10 minutes checking db values. If there is a DB value of lastseen that is more than 15 minutes long you can expire that user in the DB entry. This will not kill their session, without the session timeout. But this will show them as offline if after 15 minutes of inactivity. Hope that makes sense. what do you mean using this in teh db? you mean if i have a row, etc to specify something like runnerjp stated? Quote Link to comment https://forums.phpfreaks.com/topic/142430-currently-logged-in/#findComment-746657 Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 how can i set the session length? we did not cover that in my class that i remember. i could just have the session expire after 15 minutes correct? that is what you are saying? Yes, you can set the session timeout in the php.ini config. If you are using this in the db for the currently logged, however, you want that DB entry to expire also like runnerjp said. So, what you do, is create a CRON job or Scheduled Task and run it every 5-10 minutes checking db values. If there is a DB value of lastseen that is more than 15 minutes long you can expire that user in the DB entry. This will not kill their session, without the session timeout. But this will show them as offline if after 15 minutes of inactivity. Hope that makes sense. what do you mean using this in teh db? you mean if i have a row, etc to specify something like runnerjp stated? Right, you will have to create a new table or add a column to the user row. So a new table you would have, userid, lastseen each time a page is called you update that entry to keep the user alive. Then running a background script you can check for inactive/no longer logged in users and delete that row out of the DB if it is > x minutes. That way only users present in that table are shown as being logged in. http://www.google.com/search?hl=en&sa=X&oi=spell&resnum=1&ct=result&cd=1&q=php+who%27s+online&spell=1 There are a lot of scripts already made and tutorials on this subject. Quote Link to comment https://forums.phpfreaks.com/topic/142430-currently-logged-in/#findComment-746659 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.