How can I get information about the loged in user when I load a random website page ?
I need to grab a profile field to customize the page look
thanks
How can I get information about the loged in user when I load a random website page ?
I need to grab a profile field to customize the page look
thanks
Here's a list of a bunch of variables you can use: http://web.rhizom.nl/development/drupal-variables-in-theme-files/
This page shows how to grab variables such as the users email address: http://11heavens.com/Drupal-coder-lost-in-space/who-is-she
Erics' answer works for Themes. The standard way in modules is to do global $user
to get the logged in user. I personally don't like using globals in this way but when in rome...
The current user information is always available as a global, so you just do:
global $user;
// $user will now be a stdClass object representing the current user, logged in or not
// If you are only interested in logged in users, a standard check would be
if (0 != $user->uid) {
// Do something for/with logged in users
}
The anonymous user will have uid 0, the admin (first) user will have 1.
Profile values are always loaded in any user object obtained with the function user_load()
. The global variable $user
contains the information for the currently logged in user. If you are looking for the value of the profile named profile_realname
, you can use the following code:
global $user:
// Avoid the anonymous user, which doesn't have any profile field.
if ($user->uid) {
$realname = $user->profile_realname;
}