Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By dzedward on
How can I retrieve the username of the current user viewing a page, either using php or html..?
Comments
Hi, You can print the
Hi,
You can print the username as follows:
print_r($user->name);
I guess this will help.
You will need to initialize
You will need to initialize $user in instances.
-Craig Jackson
-Web Developer
perfect, thank you both very
perfect, thank you both very much.
Excuse me for 'hijacking'
Excuse me for 'hijacking' post, but I have similar issue.
As an admin I'm editing nodes, and I want leave my username (and perhaps editing date too), but using tips from above I'm getting username of current user instead. Any thoughts?
thanks for the answer that
thanks for the answer that works for me, i did add this into a block .Now i want to show this block only for authenticated users , and for anonymous user another block inviting them to login.how to do that plzzz?