By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,793 Members | 1,257 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,793 IT Pros & Developers. It's quick & easy.

Track Users Online with Sessions?

P: n/a
Since I'm on the topic of sesions, I've seen a few examples of tracking
online users using a mysql table and inserting the session and
timestamp and checking it at period to remove it from the list after
expiration time but is there a simpler way? Is there a way to count
how many active sessions there are open at one time? I don't care to
see user info but would like to at least know how many people are
online. I guess getting logged in users and guests would require using
a table or something. Is there any information on how to do this?
Thanks

Mar 30 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I found this and is what I'm looking for but no matter what I get '0'
for the count every time.

/* Start the session */
session_start();

/* Define how long the maximum amount of time the session can be
inactive. */
define("MAX_IDLE_TIME", 3);

function getOnlineUsers(){

if ( $directory_handle = opendir( session_save_path() ) ) {
$count = 0;
while ( false !== ( $file = readdir( $directory_handle ) ) ) {
if($file != '.' && $file != '..'){
// Comment the 'if(...){' and '}' lines if you get a significant amount
of traffic
if(time()- fileatime(session_save_path() . '\\' . $file) <
MAX_IDLE_TIME * 60) {
$count++;
}
}
closedir($directory_handle);

return $count;

} else {
return false;
}

}

echo 'Number of online users: ' . getOnlineUsers() . '<br />';

Mar 31 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.