3 Replies - 4271 Views - Last Post: 30 May 2010 - 05:52 AM Rate Topic: -----

#1 Precaseptica  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 26-December 09

Online offline function

Posted 30 May 2010 - 02:29 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: Online offline function

#2 no2pencil  Icon User is offline

  • Head MFIC
  • member icon

Reputation: 5063
  • View blog
  • Posts: 26,437
  • Joined: 10-May 07

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.
Was This Post Helpful? 1
  • +
  • -

#3 atik97  Icon User is offline

  • ???
  • member icon

Reputation: 143
  • View blog
  • Posts: 715
  • Joined: 16-September 08

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.
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.
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,740
  • Joined: 08-August 08

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1