sessions [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manjit.kool007
Forum Newbie
Posts: 4
Joined: Mon Aug 27, 2007 10:04 am

sessions [SOLVED]

Post 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
Last edited by manjit.kool007 on Wed Aug 29, 2007 10:52 am, edited 1 time in total.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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 />';
    }
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
manjit.kool007
Forum Newbie
Posts: 4
Joined: Mon Aug 27, 2007 10:04 am

but

Post by manjit.kool007 »

but then the mysql table will keep on increasing .....
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: but

Post by VladSun »

manjit.kool007 wrote:but then the mysql table will keep on increasing .....
Why? There are no INSERTs, just UPDATEs ...
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

You may also want to look at XMLHttp tutorial (who's online example) which is held in the tutorials section.
Dead_Ed
Forum Newbie
Posts: 2
Joined: Wed Aug 29, 2007 9:58 am

non-registered who's online.

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: non-registered who's online.

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
manjit.kool007
Forum Newbie
Posts: 4
Joined: Mon Aug 27, 2007 10:04 am

done it

Post by manjit.kool007 »

i have done it and it works very good enuf using the database.!!!thanq.. people!!!for u r time
Post Reply