News:

Wondering if this will always be free?  See why free is better.

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?

All Colours Sam

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?
Oh, wouldn't it be great if I *was* crazy? ...then the world would be okay
Suki

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.

All Colours Sam

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.
Oh, wouldn't it be great if I *was* crazy? ...then the world would be okay
Suki

Advertisement: