stuart7398 Posted April 9, 2008 Share Posted April 9, 2008 Hi. I wondering how i show if a user is 'online' or 'offline' do i place something in the session? if so , Code / Example / Tutorial would be apprectied. Thanks, Stuart. <code> <?php //Start session session_start(); //Check whether the session variable //SESS_MEMBER_ID is present or not if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID'])=='')) { header("location: access-denied.php"); exit(); } ?> </code> Link to comment https://forums.phpfreaks.com/topic/100314-users-online/ Share on other sites More sharing options...
Kieran Menor Posted April 9, 2008 Share Posted April 9, 2008 Well. I don't think you could ever make such a function so that it is 100% accurate. You would most likely base it off the user's activity in the last 5 or 10 minutes. I think you would need to keep a timestamp along with the user/session id in a database, then load the rows that have a timestamp that is newer than 5 minutes or whatever you decide on. Link to comment https://forums.phpfreaks.com/topic/100314-users-online/#findComment-513148 Share on other sites More sharing options...
GingerRobot Posted April 9, 2008 Share Posted April 9, 2008 If you're monitering registered and logged in users, a usual way would be to add a 'last active' field to your users table, to store a timestamp of the last time they browsed a page - you'll need to have a php file that does this updating, and include it in your other files. Your online list can then be generated by selecting those users who's last active timestamp is less than 5 (or whatever you want) minutes ago. To track guests online, you'll need to store session IDs with a similar method. Link to comment https://forums.phpfreaks.com/topic/100314-users-online/#findComment-513151 Share on other sites More sharing options...
stuart7398 Posted April 9, 2008 Author Share Posted April 9, 2008 thanks, i'll have a go at that. Link to comment https://forums.phpfreaks.com/topic/100314-users-online/#findComment-513152 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.