Page 1 of 1
sessions [SOLVED]
Posted: Tue Aug 28, 2007 11:51 pm
by manjit.kool007
hi ,
at the bottom of the home page u can see that there are 34 guests.. and new registered users etc....
and users who are logged on.
can anyone help me by supplying the code for checking all the registered users!!
Problem::
i want to user the sessions functions to check whether a user is logged on or off...
i want to display all the registered users at the bottom of the page.. can anyone suggest me a way.
people have suggested me to user a database method..
but if the user closes his browser window without logging out.. then how??
bye
Posted: Wed Aug 29, 2007 2:06 am
by s.dot
You have a field in your users table that holds a timestamp. Each time a registered user views a page, you update this field with the current timestamp.
Then you can determine whos online or offline by querying to see who has been active within the last X minutes.. 5 minutes is a common setting (PHPBB uses a 5 minute window).
Code: Select all
$timeout = time()-300; //5 minutes
$onlineResult = mysql_query("SELECT `username` FROM `users` WHERE `user_last_visit` >= '$timeout'") or die(mysql_error());
if (mysql_num_rows($onlineResult))
{
echo '<p>Users Online</p>';
while ($onlineArray = mysql_fetch_assoc($onlineResult))
{
echo $onlineArray['username'] . '<br />';
}
}
but
Posted: Wed Aug 29, 2007 9:40 am
by manjit.kool007
but then the mysql table will keep on increasing .....
Re: but
Posted: Wed Aug 29, 2007 9:47 am
by VladSun
manjit.kool007 wrote:but then the mysql table will keep on increasing .....
Why? There are no INSERTs, just UPDATEs ...
Posted: Wed Aug 29, 2007 9:53 am
by CoderGoblin
You may also want to look at
XMLHttp tutorial (who's online example) which is held in the tutorials section.
non-registered who's online.
Posted: Wed Aug 29, 2007 10:07 am
by Dead_Ed
you could also check non-registered members, but then you need to set a cron job to clear the table every now and then.
Re: non-registered who's online.
Posted: Wed Aug 29, 2007 10:13 am
by VladSun
Dead_Ed wrote:you could also check non-registered members, but then you need to set a cron job to clear the table every now and then.
Instead of a cronjob one may code it in the pages which users visit because it is not time critical issue.
done it
Posted: Wed Aug 29, 2007 10:53 am
by manjit.kool007
i have done it and it works very good enuf using the database.!!!thanq.. people!!!for u r time