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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.