2008年8月29日

$user object

Drupal: Working With Users
The $user Object
The user is represented as the global $user object, which is created during the session phase of the bootstrap process. The $user object is a join of all the fields in the users table and sessions table on the user’s ID. The anonymous user is created by drupal_anonymous_user() and looks like this:

function drupal_anonymous_user($session='') {

$user = new stdClass();
$user->uid = 0;
$user->hostname = $_SERVER['REMOTE_ADDR'];
$user->roles = array();
$user->roles[DRUPAL_ANONYMOUS_RID] = ‘anonymous user’;
$user->session = $session;

return $user;
}

To see the contents of the $user object, do

global $user;
print_r $user;

沒有留言: