News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Variable that holds the user's username?

Started by Malibuz0r, August 30, 2012, 05:52:13 PM

Previous topic - Next topic

Malibuz0r

I would like to get the user's username when let's say he's on the portal.(SimplePortal)

Anyways, I only want to show a block there but I need to get the name of the user that he's logged in with. How can I get this?

Suki

It depends on where exactly you want to show the users name, $context['member']['link'] will do that but its scope is limited to just certain areas

Most of the portals do offer a predefined block with all the user info, why don't you give it a try to that block first?
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Malibuz0r

I edited one of the blocks to see how they get the name. Here's what I got. (Tested and works)

global $memberContext, $user_info;

loadMemberData($user_info['id']);
loadMemberContext($user_info['id'], true);

$member_info = $memberContext[$user_info['id']];
echo $member_info['name'];


Topic solved.

Suki

Thats not very efficient, you are loading whats already loaded, $user_info holds, like the name implies, ll the user info, in fact, $context['member']  is just a copy of $user_info.

No need to load the data again, $user_info['name'] is already available.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Advertisement: