Gossamer Forum
Home : Products : Gossamer Forum : Development, Plugins and Globals :

Who's Online displayed on the main page!

Quote Reply
Who's Online displayed on the main page!
Here's a quick global I made to display the names of members online:

Code:
sub {

my @found = ();
my $table = $DB->table('Online','User');
my $sth = $table->select( { 'Online.online_invisible' => 0, 'Online.guest_id_fk' => 0 }, ['User.user_username'] );

while (my $userid = $sth->fetchrow_hashref) {
push @found, $userid->{user_username};
}

return 'Current members online: ' . (@found ? join(', ', @found) : 'None');

}

Thought some of you may find it useful.

(It can actually be displayed on any page as it is a global.)

Last edited by:

RedRum: Feb 28, 2002, 12:48 PM
Quote Reply
Re: [Paul] Who's Online displayed on the main page! In reply to
Hi paul !

I set a global called 'onlinemembers' in templates>>globar vars, but when i use it, it show users that are not connected, and they were not logged for several days. Pirate

Please, can you guide me on the use of this global ?

Thanx in advance Smile




http://www.webconferencia.net/
Quote Reply
Re: [webconferencia] Who's Online displayed on the main page! In reply to
It worked for me.

is there a way to show how many guests are currently online also.

Example:
Online Now:
Admin, Webmaster, SandraR
17 guests visiting

Or something like it?


Sandra Roussel
Chonsa Group Design - Fresh Start Housing
Quote Reply
Re: [SandraR] Who's Online displayed on the main page! In reply to
never mind did it by tag:


to get Current members online: & Current guests online:

Current members online:: I used the above tags


Current guests online: (in globals)

sub {
return $DB->table('Guest')->count( GT::SQL::Condition->new('guest_last_time', '>', time - 86400) );
}



Sandra Roussel
Chonsa Group Design - Fresh Start Housing

Last edited by:

SandraR: Apr 19, 2005, 3:01 PM
Quote Reply
Re: [SandraR] Who's Online displayed on the main page! In reply to
Preview?
Quote Reply
Re: [coolgreen44] Who's Online displayed on the main page! In reply to
Hi,

I believe I posted a global or two, as well as a modifed Online.pm that fixes some problems with the display and count of guests awhile back.

I've applied it to new installs, so I know it works on the current release of GF.

Hopefully, I'll have it included in the UltraWidgets Toolbox.

It's a really useful thing to see who is on-line, and get accurate counts.

I'm considering using some sort of logging/graphing to keep a count of the number of people on during the day, to monitor peak periods for guests and users. Any suggestions on what to keep would be helpful.


PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [Paul] Who's Online displayed on the main page! In reply to
I have tried this global and have found that it also displays Invisible users. Can it be adapted so it hides invisible users usernames from the list?

Thanks
Quote Reply
Re: [MJB] Who's Online displayed on the main page! In reply to
Here's what I use on http://www.tantell.com:

Code:
sub {
$DB->table('Online')->delete(GT::SQL::Condition->new(online_time => '<' => (time - $CFG->{online_timeout} * 60)));
my @found;
my $user_name;
my $table = $DB->table('Online','User');
$table->select_options ('ORDER BY user_username ASC');
my $sth = $table->select( { 'Online.online_invisible' => 0, 'User.user_invisible' => 0, 'Online.guest_id_fk' => 0 }, ['User.user_username']);

while (my $userid = $sth->fetchrow_hashref) {

$user_name = $userid->{user_username};

push @found, "<font size=1><A Href=\"/cgi-bin/gforum/gforum.cgi?username=$userid->{user_username}\">$userid->{user_username}</A></font>";

}

return (@found ? \join(',&nbsp;', @found) : 'None');
}

Just change the part that reads "/cgi-bin/gforum/gforum.cgi", to your correct path.

Then I use the following at the top of my category_list.html template:

Code:
<font size=2><a href="<%cgi_root_url%>/gforum.cgi?do=whos_online"><i>Users Online</i></a> <i>(Members: <%online_member_count%>, Guests: <%online_guest_count%>)</i>: </font><%whos_online(%current_user_username%)%>

Hope that helps!

Sean
Quote Reply
Re: [SeanP] Who's Online displayed on the main page! In reply to
Code:
'User.user_invisible' => 0,

That's the part that was missing from my global.

Thanks. Smile
Quote Reply
Re: [SandraR] Who's Online displayed on the main page! In reply to
I noticed that the online_guest global never displayed the same amount of guests as the Who's Online page. Also, when using it with SSI, the page that it is displayed on counts visitors when they access that page and are not on the forum.

To fix this replace the global:

Code:
sub {
return $DB->table('Guest')->count(GT::SQL::Condition->new('guest_last_time', '>', time - 86400));
}

with:

Code:
sub {
return $DB->table('Online')->count(GT::SQL::Condition->new(guest_id_fk => '<' => (time - $CFG->{online_timeout} * 60)));
}

( More: http://www.gossamer-threads.com/...i?post=290515#290515 )

Last edited by:

MJB: Jul 21, 2006, 2:55 PM