What variable is the currently logged in user's username stored in?

Comments

simul’s picture

$user

you can try by creating a i.e. new page (input format should be php) and pasting the following code:

global $user;
print_r($user);

and you will see all the details of the current user

hth

dudez12’s picture

How do you get it to just display the username?

Chill35’s picture

global $user;
print $user->name;

You can look at the article "Who am I" on my web site (link below).

simul has a very good idea : using print_r in a page with php input format, to examine what you've got available inside the variable $user.

Caroline
Who am I | Where are we
11 heavens

simul’s picture

$user -> name
and you print it out by

echo $user -> name;

technical details:
all the information about users is saved in a mysql table ("users") which has many fields like uid, name, pass, mode, threshold, signature etc. Drupal queries that table, create the php object $user and attach into it all the fields of the table "users". Then you can print each of these fields by using -> operator.
hth