1. 6.x developer/globals.php user
  2. 7.x developer/globals.php user

An object representing the user currently visiting the site.

Contains preferences and other account information for logged-in users. When a user is not logged-in, $user->uid property is set to 0.

Contains preferences and other user information.

File

developer/globals.php, line 85
These are the global variables that Drupal uses.

Code

global $user;

Comments

xangelo’s picture

This information doesn't seem to be on the website although it makes sense to show up here. This is what $user actually contains.

stdClass Object
(
    [uid] => 
    [name] => 
    [pass] => 
    [mail] => 
    [mode] => 0
    [sort] => 0
    [threshold] => 0
    [theme] => 
    [signature] => 
    [signature_format] => 0
    [created] => 1268923269
    [access] => 1279119654
    [login] => 1278690259
    [status] => 1
    [timezone] => -18000
    [language] => 
    [picture] => 
    [init] => 
    [data] => a:3:{s:18:"admin_compact_mode";b:0;s:5:"block";a:1:{s:5:"views";a:1:{s:13:"Users-block_1";i:1;}}s:13:"form_build_id";s:37:"form-f7c8717b2298f8883cb5a3b46bfc12f8";}
    [sid] => b23b8gii6mcqftfft240di35d7
    [hostname] => 0.0.0.0
    [timestamp] => 1279119654
    [cache] => 0
    [session] => views|N;user_overview_filter|a:0:{}dblog_overview_filter|a:0:{}messages|a:1:{s:6:"status";a:1:{i:0;s:15:"Caches cleared.";}}
    [admin_compact_mode] => 
    [block] => Array
        (
            [views] => Array
                (
                    [Users-block_1] => 1
                )

        )

    [form_build_id] => form-f7c8717b2298f8883cb5a3b46bfc12f8
    [roles] => Array
        (
            [rid] => name
        )

)
voj’s picture

If you are confuse on which reference keys or values are declared and to show their values you can use the php function print_r();

function print_r($array = array || object)
  returns string - human-readable array or object structure of the given argument.

global $user;
// example
print_r($user);

declare it anywhere on your codes and you will see the value of the array on the top of the page before anything else.

You can use this function when debugging, specially in drupal because it uses a lot of arrays and objects.

msellers’s picture

Don't assume that you can access the global $user object to get all contrib module added user info. Contrib modules add information to the $user object using hook_user. The only reliable way to get this additional data is through a user_load function call. This may change in some future release of Drupal. See http://drupal.org/node/57287