Hey guys.
First thread from me. I normally crack my own issues, but this one I need a little help with.
I'm building a forum at the moment, and for this forum I require the well renowned function that allows people to see if a poster is online or offline.
How exactly do I work my way around this?
Will I have to create an extra table in my db, to store login sessions and handle the whole shabang this way, or is there a simpler way to do it?
Regards
Online offline functionFor a forum
Page 1 of 1
3 Replies - 16121 Views - Last Post: 30 May 2010 - 05:52 AM
Replies To: Online offline function
#2
Re: Online offline function
Posted 30 May 2010 - 02:37 AM
I followed this tutorial as a guideline to setup the database columns & values to monitor usage by member & time. This will allow you to achieve what you are trying to do, but you will need to tinker with the code a bit as the main focus of the tutorial is something different.
#3
Re: Online offline function
Posted 30 May 2010 - 03:21 AM
You need to create a new column in your users table.
Then you need to put these code in every pages where the user has access in the forum.
where the status field is updated with time() after checking the userID which need to be stored in a session variable.
Now you will have some code to display post, username of the author etc. To display the user online/offline status, add the following code in the scope where you are displaying each individual code-
where $row is returned from mysql query of users table and here a check is done to decide whether to display online/offline message.
Hope this will help you.
Then you need to put these code in every pages where the user has access in the forum.
session_start(); if(isset($_SESSION["userID"])) { $setLogged=mysql_query("UPDATE users SET status='".time()."'WHERE user_id='".$_SESSION["userID"]."'") or die(mysql_error()); }
where the status field is updated with time() after checking the userID which need to be stored in a session variable.
Now you will have some code to display post, username of the author etc. To display the user online/offline status, add the following code in the scope where you are displaying each individual code-
$loggedTime=time()-120; //2 minutes if($row['status']>$loggedTime) { echo "<img src='online.jpg'/>"; } else { echo "<img src='offline.jpg'/>"; }
where $row is returned from mysql query of users table and here a check is done to decide whether to display online/offline message.
Hope this will help you.
#4
Re: Online offline function
Posted 30 May 2010 - 05:52 AM
I would create a separate table containing two fields: the user id field and the datetime of their last activity. When ever a logged in user does anything, the datetime would be updated, but just before that I'd run a query to remove all records whose datetime is less than X minutes/seconds ago. Then it's just a matter of using a query to see who is online.
If you want to get fancy like this site, you could use a third field containing the forum where the activity is taking place.
If you want to get fancy like this site, you could use a third field containing the forum where the activity is taking place.
Page 1 of 1