in reply to how do to a 'who is online' feature

any and all suggestions would be appreciated

arthas's answer is essentially correct. If "database" intimidates you, think "cache". A flat file works, though you'll be rewriting it each time you record a page hit from a user. Depending on your site load, this may or may not be an issue.

No matter how you decide to capture data, it suffices to record a username and a "last visited" timestamp. The timestamp is used to determine who to show as being online. You might, for example, say that any user who has hit the website within the last 5 minutes is "online". Depending on how you're keeping records, the timestamp can also be used to expire a user from the cache.

  • Comment on Re: how do to a 'who is online' feature

Replies are listed 'Best First'.
Re: Re: how do to a 'who is online' feature
by zengargoyle (Deacon) on May 21, 2003 at 11:15 UTC

    indeed, and if you think "cache" you should check out Cache::Cache.

    my $who_here = Cache::FileCache->new( default_expires_in => 300, # 5 minutes ); # reset current user expiration time $who_here->set($user, 1) if have_valid_user(); # if you have session data you can store it instead of # the '1' with the side benefit of logging out users # after inactivity # # my $userinfo; # unless ($userinfo = $who_here->get($user)) { # ... make them login again # $who_here->set($user, { src_ip => 'foo', favorite_colour => 'green' + }); # } else { # $userinfo has session info # print "your favorite colour is $userinfo->{favorite_colour}<br>"; # } my @who_here_now = $who_here->get_keys(); print "there are ", scalar @who_here_now, " recent visitors:<br>"; print "$_<br>" for @who_here_now;