0

Hai, i'm new to cookies/sessions, so i'm not sure how to do this. So, theres a row in the user account table called 'online'. When their online, the value is 1. When their offline, the value is 0. I'm not sure how to do this, like to store a cookie then remove it when they leave? Halp please :D

5
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by mschroeder
0

If everyone is required to sign-in, then you can update the "online" indicator when they sign in. When they sign out or after they have been inactive for a certain amount of time, you can reset it to "offline". If you can also have active users who aren't signed in (just browsing), then you can also get the total count of active sessions - see the link below:

http://www.olate.co.uk/articles/131

1

The simplest way to do this is to make a column to store the last time the user was active. E.g:

// Before end of script
$time = time();
mysql_query("UPDATE Members SET last_active='$time' WHERE memberid=$memberid", $con);

Then to check if a user is online or not, choose a window of activity(say, 1 minute).

$inactive = bcsub(time(), 60);
$query = "SELECT * FROM Members WHERE last_active > $inactive";
$result = mysql_query($query, $con);

One thing to keep in mind: Some users may not log out, or may just go away from the comp with the window still up, leaving their session active far past when they should really be considered online. Figure out how you want to define an "online" user.

Edited by Lsmjudoka: n/a

0

You could also override the default session handler, and set it up to instead use a database table to store sessions. A count of the rows in the table will yield your currently active session list.

This also sets you up to be able to use your sessions across multiple servers and gives you the ability to kill all user's logged in sessions for something like maintenance mode etc.

http://www.php.net/manual/en/function.session-set-save-handler.php

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.