How to get user info from $user class

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Anti-Spam Guide
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
Locked
User avatar
Destructerator
Registered User
Posts: 8
Joined: Thu Apr 12, 2007 11:57 pm

How to get user info from $user class

Post by Destructerator »

Hi guys, I'm fairly new to PHP/SQL, and I'm attempting to integrate my site with phpBB3. What I need right now is a way to get the logged-in user's information from this code here somehow:

Code: Select all

define('IN_PHPBB', true);
$phpbb_root_path = 'forum/'; //relative path to phpBB3 forum directory
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
I need to get the typical member stuff like their new messages, their name, ID, etc so that I can put it in the pages of my site while they are logged in. Is $user an array of some sort I can just pull the data out with something like $user['username'], or is there something I'm missing?
User avatar
karlsemple
Former Team Member
Posts: 39802
Joined: Mon Nov 01, 2004 8:54 am
Location: Hereford, UK
Contact:

Re: How to get user info from $user class

Post by karlsemple »

Code: Select all

$user->data['username']
is the username

Code: Select all

$user->data['user_id']
is the user id and so on, in phpBB2 the user array was

Code: Select all

$userdata['']
in phpBB3 is has been replaced by

Code: Select all

 $user->data['']
also in future can you make sure that support topics are posted in the support forum which is where I will move this, thanks :)
Image
niks999
Registered User
Posts: 29
Joined: Wed Apr 11, 2007 8:31 am

Re: How to get user info from $user class

Post by niks999 »

So...

If i want to put the name of the user wich is logged in, in the overall_header.html, like :
Welcome (username) !

So what shud i do ?

Thnx in advance ;)
User avatar
karlsemple
Former Team Member
Posts: 39802
Joined: Mon Nov 01, 2004 8:54 am
Location: Hereford, UK
Contact:

Re: How to get user info from $user class

Post by karlsemple »

niks999 wrote:So...

If i want to put the name of the user wich is logged in, in the overall_header.html, like :
Welcome (username) !

So what shud i do ?

Thnx in advance ;)

You would,

Open language/en/common.php

Find:

Code: Select all

'WROTE'						=> 'wrote',
After Add:

Code: Select all

'WELCOME_USER'              => 'Welcome %s',
Open includes/functions.php

Find:

Code: Select all

'L_ONLINE_EXPLAIN'	=> $l_online_time,
After Add:

Code: Select all

'L_WELCOME_USER'    => sprintf($user->lang['WELCOME_USER'], $user->data['username']),
Open styles/template/overall_header.html

Place

Code: Select all

{L_WELCOME_USER}
in the file where you want it to say Welcome username.
Image
niks999
Registered User
Posts: 29
Joined: Wed Apr 11, 2007 8:31 am

Re: How to get user info from $user class

Post by niks999 »

It works....

But i want it to look exactly like a username appears everywhere i.e with the usergroup color & link to the profile....

Moreover, when we log out, it shows Anonymous, can it be changed to Guest ??
User avatar
karlsemple
Former Team Member
Posts: 39802
Joined: Mon Nov 01, 2004 8:54 am
Location: Hereford, UK
Contact:

Re: How to get user info from $user class

Post by karlsemple »

Replacing

Code: Select all

'L_WELCOME_USER'    => sprintf($user->lang['WELCOME_USER'], $user->data['username']),
with

Code: Select all

'L_WELCOME_USER'    => ($user->data['is_registered']) ? sprintf($user->lang['WELCOME_USER'], get_username_string('full', $user->data['user_id'], $user->data['username'], $user->data['user_colour'])) : 'Guest',
Image
Locked

Return to “[3.0.x] Support Forum”