Jump to content

Users Online


stuart7398

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.