Users Online

This is an archive of the phpBB 2.0.x support forum. Support for phpBB2 has now ended.
Forum rules
Following phpBB2's EoL, this forum is now archived for reference purposes only.
Please see the following announcement for more information: viewtopic.php?f=14&t=1385785
Locked
WhiskeyMike
Registered User
Posts: 6
Joined: Fri Feb 01, 2008 6:17 pm

Users Online

Post by WhiskeyMike »

This may have already been addressed but after going through about 60 results pages, I gave up. I'm trying to do some integration. I've successfully done the login/logout with no problems. Now I'm trying to see if there's a script that will not only show how MANY people are online, but who they are.

An actual list of usernames that are currently online, like at the bottom of the forum index... only for use on a non PHPBB page.
User avatar
Lumpy Burgertushie
Registered User
Posts: 69223
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: Users Online

Post by Lumpy Burgertushie »

WhiskeyMike wrote:This may have already been addressed but after going through about 60 results pages, I gave up. I'm trying to do some integration. I've successfully done the login/logout with no problems. Now I'm trying to see if there's a script that will not only show how MANY people are online, but who they are.

An actual list of usernames that are currently online, like at the bottom of the forum index... only for use on a non PHPBB page.
I assume that you have created your login pages by adding the phpbb code to the top of them.

anyway, you have to do that to any page that you want to put phpbb code in.

once you have the phpbb sessions code in your page, just copy the relevant code from the tpl file to your other page.


robertt
Premium phpBB 3.3 Styles by PlanetStyles.net

I am pleased to announce that I have completed the first item on my bucket list. I have the bucket.
WhiskeyMike
Registered User
Posts: 6
Joined: Fri Feb 01, 2008 6:17 pm

Re: Users Online

Post by WhiskeyMike »

That didn't work. I do have the top code for all integrated pages. The .tpl file: "viewonline_body.tpl" contains variables (I guess, not your typical $ variables) that look like this:

{guest_user_row.USERNAME}

These don't come back with any value, and just write the exact same thing on the .php
User avatar
dellsystem
Former Team Member
Posts: 3879
Joined: Sat Apr 09, 2005 8:54 pm
Location: Montreal
Name: Wendy
Contact:

Re: Users Online

Post by dellsystem »

Take a look at viewonline.php to see how it's done. You could create a separate page in includes/ called viewonline.php and then include that for each page you want to show the list of users on.
Here's what it might look like:

Code: Select all

<?php


//
// Get user list
//
$sql = "SELECT u.user_id, u.username, u.user_allow_viewonline, u.user_level, s.session_logged_in, s.session_time, s.session_page, s.session_ip, u.user_session_time, s.session_start
	FROM ".USERS_TABLE." u, ".SESSIONS_TABLE." s
	WHERE u.user_id = s.session_user_id
		AND s.session_time >= ".( time() - 300 ) . "
	ORDER BY u.username ASC, s.session_ip ASC";
if ( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Could not obtain regd user/online information', '', __LINE__, __FILE__, $sql);
}

$guest_users = 0;
$registered_users = 0;
$hidden_users = 0;

$reg_counter = 0;
$guest_counter = 0;
$prev_user = 0;
$prev_ip = '';

while ( $row = $db->sql_fetchrow($result) )
{
	$view_online = false;

	if ( $row['session_logged_in'] ) 
	{
		$user_id = $row['user_id'];

		if ( $user_id != $prev_user )
		{
			$username = $row['username'];

			// SIMPLE COLORED USERGROUPS MOD START

			$style_color = ($user_color = color_groups_user($row['user_id'])) ? 'style="font-weight:bold;color: #' . $user_color . '"' : '';

			$username = '<span ' . $style_color . '>' . $username . '</span>';

			// COLOR GROUPS END

			if ( !$row['user_allow_viewonline'] )
			{
				$view_online = ( $userdata['user_level'] == ADMIN ) ? true : false;
				$hidden_users++;

				$username = '<i>' . $username . '</i>';
			}
			else
			{
				$view_online = true;
				$registered_users++;
			}

			$which_counter = 'reg_counter';
			$which_row = 'reg_user_row';
			$prev_user = $user_id;
		}
	}
	else
	{
		if ( $row['session_ip'] != $prev_ip )
		{
			$username = $lang['Guest'];
			$view_online = true;
			$guest_users++;
	
			$which_counter = 'guest_counter';
			$which_row = 'guest_user_row';
		}
	}

	$prev_ip = $row['session_ip'];
	if ( $view_online )
	{
		if ( $row['session_page'] < 1 || !$is_auth_ary[$row['session_page']]['auth_view'] )
		{
			switch( $row['session_page'] )
			{
				case PAGE_INDEX:
					$location = 'Site index';
					$location_url = "index.$phpEx";
					break;
				case PAGE_ABOUT:
					$location = 'Browsing about page';
					$location_url = "about.$phpEx";
					break;
				case PAGE_FORUM:
					$location = 'Forum index';
					$location_url = "forum.$phpEx";
					break;
				case PAGE_POSTING:
					$location = 'Posting a message';
					$location_url = "index.$phpEx";
					break;
				case PAGE_READING:
					$location = 'Viewing a post';
					$location_url = "index.$phpEx";
					break;
				case PAGE_LOGIN:
					$location = 'Logging in';
					$location_url = "login.$phpEx";
					break;
				case PAGE_SEARCH:
					$location = 'Searching';
					$location_url = "search.$phpEx";
					break;
				case PAGE_PROFILE:
					$location = 'Viewing a profile';
					$location_url = "index.$phpEx";
					break;
				case PAGE_VIEWONLINE:
					$location = 'Viewing online users';
					$location_url = "viewonline.$phpEx";
					break;
				case PAGE_ADMIN:
					$location = 'Administration control panel';
					$location_url = "adm/index.$phpEx";
					break;
				case PAGE_VIEWMEMBERS:
					$location = 'Viewing memberlist';
					$location_url = "memberlist.$phpEx";
					break;
				case PAGE_PRIVMSGS:
					$location = 'Browsing mailbox';
					$location_url = "privmsg.$phpEx";
					break;
				case PAGE_FAQ:
					$location = 'Viewing FAQs';
					$location_url = "faq.$phpEx";
					break;
				case PAGE_GAMES:
					$location = 'Playing games';
					$location_url = "games.$phpEx";
					break;
				case PAGE_USERCP:
					$location = 'Browsing user control panel';
					$location_url = "usercp.$phpEx";
					break;
				default:
					$location = 'about';
					$location_url = "index.$phpEx";
			}
		}
		else
		{
			$location_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . '=' . $row['session_page']);
			$location = $forum_data[$row['session_page']];
		}

		$reg_ip = decode_ip($row['session_ip']);
		$last_update = create_date($userdata['user_dateformat'], $row['user_session_time'], $userdata['user_timezone']);
		$session_start = create_date($userdata['user_dateformat'], $row['session_start'], $userdata['user_timezone']);
		$each .= ( $$which_counter % 2 ) ? '<tr class="row2">' : '<tr class="row1">' ;
		$each .= '<td><a href="../viewprofile.php?id=' . $row['user_id'] . '">' . $username . '</a></td><td>' . $session_start . '</td><td>' . $last_update . '</td><td><a href="' . $phpbb_root_path . $location_url . '">' . $location . '</a></td><td>' . $reg_ip . '</td></tr>';
		$$which_counter++;
	}
}

if( $registered_users == 0 )
{
	$l_r_user_s = $lang['Reg_users_zero_online'];
}
else if( $registered_users == 1 )
{
	$l_r_user_s = $lang['Reg_user_online'];
}
else
{
	$l_r_user_s = $lang['Reg_users_online'];
}

if( $hidden_users == 0 )
{
	$l_h_user_s = $lang['Hidden_users_zero_online'];
}
else if( $hidden_users == 1 )
{
	$l_h_user_s = $lang['Hidden_user_online'];
}
else
{
	$l_h_user_s = $lang['Hidden_users_online'];
}

if( $guest_users == 0 )
{
	$l_g_user_s = $lang['Guest_users_zero_online'];
}
else if( $guest_users == 1 )
{
	$l_g_user_s = $lang['Guest_user_online'];
}
else
{
	$l_g_user_s = $lang['Guest_users_online'];
}

?>
Then, for the actual non-phpBB page, you could either echo $each or assign a template variable to each, under $template->assign_vars, as in 'LOGGED_IN_LIST' => $each,
Although my $each looks like

Code: Select all

		$each .= ( $$which_counter % 2 ) ? '<tr class="row2">' : '<tr class="row1">' ;
		$each .= '<td><a href="../viewprofile.php?id=' . $row['user_id'] . '">' . $username . '</a></td><td>' . $session_start . '</td><td>' . $last_update . '</td><td><a href="' . $phpbb_root_path . $location_url . '">' . $location . '</a></td><td>' . $reg_ip . '</td></tr>';
because it's displayed in a table, you may want to just display in a list, separated by commas. In that case:

Code: Select all

$each .= '<a href="profile.' . $phpEx . '?mode=viewprofile&u=' . $row['user_id'] . '">' . $username . '</a>, ';
You'll also need to edit the

case PAGE_PROFILE:
$location = 'Viewing a profile';
$location_url = "index.$phpEx";
break;

parts to reflect the pages of your website.

Moving to support
Former moderator and website team member | My MODs, and more (GitHub)
yenerich
Registered User
Posts: 27
Joined: Sat Apr 01, 2006 9:15 pm

Re: Users Online

Post by yenerich »

Very interesting!!

I tried to do the same in one portal of mine, to show in the main page who are online. But i cant achieve yet, i will follow directions on this thread.
andr74
Registered User
Posts: 7
Joined: Mon Nov 24, 2008 2:21 pm
Contact:

Re: Users Online

Post by andr74 »

I do the same, but result is bad.
Locked

Return to “2.0.x Support Forum”