I would approach the problem directly. Basically what you want to know is
the users who have an active session. So scan the folder where the PHP
session files are kept--you can obtain the path with a call to
session_save_path(). Open each of them and pass the content to
session_decode() to get the variables in the sessions.
$current_sess_str = session_encode(); // save current session
$active_sessions = array($_SESSION); // add the current session to the
list
$sess_path = session_save_path();
if($dir = opendir($sess_path)) {
while($file = readdir($dir)) {
if(is_file("$sess_path/$file")) {
if($sess_str = @file_get_contents("$sess_path/$file")) {
$_SESSION = array();
session_decode($sess_str);
$active_sessions[] = $_SESSION;
}
}
}
}
$_SESSION = array();
session_decode($current_sess_str); // restore current session
When the session expires or when you call session_destroy(), PHP removes the
session file.
Uzytkownik "David" <bi****@hotmail.com> napisal w wiadomosci
news:3e**************************@posting.google.c om...
I am setting up a web community with a feature that will display
whether or not a member is currently online.
I intend on implementing this by holding a column in the dbase simply
called online. When a user logs on, the status of this will be updated
to yes.
When the user clicks to log out, we simply change the state of this
field to no.
The problem comes when a user does not execute the log out script and
simply closes their browser, effectively logging them out.
How can I keep the state of the online attribute accurate? I have had
a few ideas such as using a JavaScript sniffer which detects when the
windows is closed then updates the dbase, however I don't believe such
a jscript exists?
Another possible solution would be to have a cron job but Im not sure
what the cron would check for and I feel there must be a better way
anyway!
Any suggestions welcomed!