Hey,

I need to be able to display the currently logged in username on my clients website (http://www.rdl101.com). You will see when you go to the site there is a dashboard type bar at the top, that says "Hey , welcome to RDL101.COM". I need the username to be displayed just after the Hey.

Thanks to anyone who can come up with a solution in advanced, I've tried using the print $user->name but that doesn't show anything.

Comments

krishnarp’s picture

Hi
Try this
global $user;
$name = $user->name;

Cheers
Krishna

cgweb’s picture

Thanks but that doesnt work either, but could you expand..

i put global $user; $name = $user->name; where i wanted it.. is that right?

krishnarp’s picture

HI
You want to concatenate '$name' with the code like
"Hey ".$name." Welcome ..."

Regards
Krishna

cgweb’s picture

Again, thanks but No luck :(

leadstudios’s picture

You are on the right track.

Stick <? global $user; ?> somewhere at the top.

Now use print $user->name where ever you want to put the user name.

cgweb’s picture

THANK YOU! That works =D

franciscohm’s picture

Thank you! :-)

ceccoo’s picture

Hello,

is that still in Drupal 9 the solution? Thank you!

Stick <? global $user; ?> somewhere at the top.

Now use print $user->name where ever you want to put the user name.

I'm beginner, were is "somewhere at the top"? How can this code print $user->name be used?

cgallo’s picture

Hello, I have a similar problem. I need to display the user First name and last name instead of the username. How can I do this???

leadstudios’s picture

I am assuming you are using the profile module with fields for first name and last name? Have a look at the documentation on customizing the user profile layout. It should tell you how to display your 2 custom fields.

cgallo’s picture

Hello,
I am actually using the LDAP authentication module to authenticate to Novell. I looked at the documentation but still can't figure out how to display this info from LDAP. Thanks for the help, please let me know if you need more info.

leadstudios’s picture

I've never used the LDAP module so you are probably better off posting it the modules' support requests. I imagine it shouldn't be difficult so long as the firstname/lastname are in a table to retrieve based on the uid which you will have once the user logs in.

cgallo’s picture

I found a way to display fname and lname from ldap. Please post if anybody needs solution.

fnikola’s picture

Yes, I am interested in displaying the fname and lname from ldap. I've been reading a thread on mapping profile fields to ldap, but have not had any success to date. Thanks!

beautifulmind’s picture

Well, if you found the solution, all of us need it. Just post it, b'coz any day, any time, any one will need it.

:)
Beautifulmind
Know more

Regards.
🪷 Beautifulmind

JoseFelix’s picture

Thanks for this answer!
I was looking for this :)
_________________
Owner of Diets Wonder - Wondering what kind of diets out there works!