Add another column to the Users tablE, call it "LastActivity" - Source talked about this.
Everytime you check if the user is logged in, update that column with the "time()" function
eg:
I do this when I check if the users logged in (exactly the same function name as Caleb uses ;o "checkLogin()")PHP Code:mysql_query( 'UPDATE `Users` SET `LastActivity` = "' . time() . '" WHERE `id` = "' . $userID . '" LIMIT 1;' );
Now to get all the users who are logged in:
Thats a basic timeout for you. I use that to log the user out if they been inactive too long too.PHP Code:<?php
$mysqlUsers = mysql_query( 'SELECT * FROM `Users`' ) or die( 'Die' );
if( mysql_num_rows( $mysqlUsers ) >= 1 )
{
$loggedIn;
while( $r = mysql_fetch_array( $mysqlUsers ) )
{
$timeOut = 60 * 30; // 30 Minutes (Timeout)
// Below is checking the time difference between their last inactivity and now, then checking it against 30mins ($timeOut )
if( ( $r[ 'LastActivity' ] - time() ) <= $timeOut )
{
$loggedIn .= $r[ 'UserName' ] . ' ';
// ^^ Add to the list of loggedIn users.
}
}
echo $loggedIn;
}
?>





Reply With Quote
