[ic] Displaying Users Online

Dave Barr interchange-users@interchange.redhat.com
Fri Jan 18 12:06:19 2002


At 13:07 -0500 17/1/02, cfm@maine.com wrote:
>On Thu, Jan 17, 2002 at 09:15:06AM -0800, Ed LaFrance wrote:
>>  At 05:57 PM 01/16/2002 -0800, you wrote:
>>  >Hi All,
>>  >
>>  >I need to show the # of user's currently logged in.  Can someone help?
>>  >
>>  >Output example of what I need...
>>  >
>>  >User's Currently Online: [code here]
>>
>>  I would suggest using the [counter] tag.  Set up a file called
>>  etc/logged_users, increment it each time someone logs in, and decrement it
>>  when someone logs out. The you can do:
>>
>>  User's Currently Online: [counter file=etc/logged_users value=1]
>
>
>We've started to keep a session hash for the catalog as a whole.
>
>So you'd write a tag that would put the user logged in into a
>hash when they log in, with whatever attributes
>
>%SESSION={
>	%LOGGED_IN={
>		    %user1=>{
>                              attr1=>asdf
>                              attr2=>asdf
>                              attr3=>asdf
>			     timestamp1=>now()
>			     }
>		     }
>	%TIMESTAMPS={
>                      'timestamp1'=>[$SESSION->{LOGGED_IN}->$user1,...
>                      'timestamp2'=>[$SESSION->{LOGGED_IN}->$user2,...
>          }
>}
>
>Just guessing at the structure; we don't actually do this for users
>but for "rare items" in carts, decrementing inventory on a temporary
>basis.  You do want some sort of timestamp index so you can expire
>logins automatically.
>
>Then you'd put a tag or autoload function that checks login status
>and init session if too long or not found, blow away old data, that
>sort of thing.
>

This is my *very* lax version, doesn't take into account users who 
log out or quit the browser, it only returns how many sessions are 
current (last 60 mins).

[calc]
   my $sessions = q{[dump-session find=1]};
   my @array = split(/\s+/, $sessions);
   my $num = @array;
   my $out = "Shopping Network Users: " . $num;
   return $out;
[/calc]

Dave
-- 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dave Barr        eCommerce Technical Manager      CricInfo Ltd
www.cricinfo.com   dave.barr@cricinfo.com    shop.cricinfo.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~