Yep very true this is what i did
STEP 1
on my user or login table i added these at the end
`conected_usr` char(1) COLLATE latin1_general_cs DEFAULT 'N',
`tm_usr` datetime DEFAULT '0000-00-00 00:00:00',
both of them i set them to NULL
STEP 2
Open up the login page:
on the login page instead of making the log table wich i have for other propose (i made my logs kind of addt style so i didnt want to use that one)
i did an update single record with data assist filtered by the User session ID and binded "Y" value to my conected_usr field and the exact date for tm_usr, this to our users table or login table
Save the login page.
STEP 3
Open up your logout.php page or how ever you name it and added with data assist an update again similiar to the login page but with the conected_usr binded value to "N" and also update the tm_usr field for the exact datetime.
STEP 4
Create a new page called whoischeck.php or what ever name you like
i first used security assist on a comon place with the show if region and modify it to this script also add your conecction on top of all
<?php require_once('../Connections/conectpage.php'); ?>
<?php require_once( "../WA_SecurityAssist/Helper_PHP.php" ); ?>
<?php
////// To update session status for user table to get who is online ////////
if(WA_Auth_RulePasses("Logged in to users")){ // Begin Show Region
$tm=date("Y-m-d H:i:s");
$xses=$_SESSION['UsID'];
$q=mysql_query("update usertb set conected='Y',tm='$tm' where UserID='$xses'");
//echo "<center><font face='Verdana' size='2' ><br>Welcome $xses Click <a href=logout.php>here to logout</a> | <a href=change-password.php>Change Password</a>| <a href=update-profile.php>Update Profile</a><br></center></font>";
echo $tm;
echo mysql_error();}
else{
//echo "<center><font face='Verdana' size='2' ><a href=login.php>Already a member, please Login</a> </center></font>";
}
///// ////////////// End of updating login status for who is online ///////
// Find out who is online /////////
$gap=10; // change this to change the time in minutes, This is the time for which active users are collected.
$tm=date ("Y-m-d H:i:s", mktime (date("H"),date("i")-$gap,date("s"),date("m"),date("d"),date("Y")));
//// Let us update the table and set the status to OFF
////for the users who have not interacted with
////pages in last 10 minutes ( set by $gap variable above ) ///
$ut=mysql_query("update usertb set conected='N' where tm < '$tm'");
echo mysql_error();
/// Now let us collect the userids from table who are online ////////
$qt=mysql_query("select UsID from usertb where tm > '$tm' and conected='Y'");
echo mysql_error();
while($nt=mysql_fetch_array($qt)){
//echo "$nt[UsID],";
}
?>
STEP 5
This last file i include it to the sites footer so it loads on every page and also i set a cronjob in order to check every hour if the user table has activity or not, but havent test it yet, the cronjob on cpanel host is something like this
php -q /home/accountname/public_html/crons/whoischeck.php
STEP 6
Now at my administration part i created a file to show me users conected or not conected, i also built a little ticket thing wich allows me to msg quickly users and they will get an icon to check the site msg like a small chat, it also usefull if your building your own forum or message boards.
Hope this helps
Sades
Pd. i have still not tested on a live server yet if any one use this please let us know also if you modify it i just grabbed a tutorial and took the parts mostly for the cronjob to be applyed