plznty Posted December 21, 2010 Share Posted December 21, 2010 I would like my website to show which users are logged in. Is there a simple way of retrieving all session ids from the server that have been allocated and are active in order to do this? I know this could lead to faulty information, but would appear to be the simplest and reliable. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/222273-user-sessions-to-determine-accounts-logged-in/ Share on other sites More sharing options...
denno020 Posted December 21, 2010 Share Posted December 21, 2010 is session information stored at the server or in the users browser? I would think the best way for this would be to set a flag in your db that says if they're logged in or not.. This wouldn't be very hard at all if you already have a users table with their information. I'm not very well versed in sessions though, so I could be incorrect with my assumption above. Denno Quote Link to comment https://forums.phpfreaks.com/topic/222273-user-sessions-to-determine-accounts-logged-in/#findComment-1149784 Share on other sites More sharing options...
BK87 Posted December 21, 2010 Share Posted December 21, 2010 <?php echo ini_get( 'session.save_path'); ?> whats where all the sessions are stored.. Just make a script to calculate how many files are in that folder... thats how many active sessions there are. Quote Link to comment https://forums.phpfreaks.com/topic/222273-user-sessions-to-determine-accounts-logged-in/#findComment-1149786 Share on other sites More sharing options...
trq Posted December 21, 2010 Share Posted December 21, 2010 <?php echo ini_get( 'session.save_path'); ?> whats where all the sessions are stored.. Just make a script to calculate how many files are in that folder... thats how many active sessions there are. That won't get you 'who' is logged in. The method denno020 suggested is the typical method used. You simply update a timestamp every time a user hits a page. You then (where you want to display the logged in users) query for all users with a timestamp within the last ten minutes and display them, the rest can be removed (all in this same process). Quote Link to comment https://forums.phpfreaks.com/topic/222273-user-sessions-to-determine-accounts-logged-in/#findComment-1149788 Share on other sites More sharing options...
BK87 Posted December 21, 2010 Share Posted December 21, 2010 <?php echo ini_get( 'session.save_path'); ?> whats where all the sessions are stored.. Just make a script to calculate how many files are in that folder... thats how many active sessions there are. That won't get you 'who' is logged in. The method denno020 suggested is the typical method used. You simply update a timestamp every time a user hits a page. You then (where you want to display the logged in users) query for all users with a timestamp within the last ten minutes and display them, the rest can be removed (all in this same process). ahh yes, didn't fully read his post... you're right Quote Link to comment https://forums.phpfreaks.com/topic/222273-user-sessions-to-determine-accounts-logged-in/#findComment-1149794 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.