I created a personal profile page called 'user_profile_tpl.php'.

In this page I need to recover the uid of the user is logged, but when i print the $user->uid, the id that it is returned me is of the user who is being edited and not of what he is logged.

How to i get the uid of the user is logged?

Comments

lenkkivihko’s picture

I use $user->uid in my custom profile page to create the custom profile page for each user.

when I want to get the uid of person who has written a node I use

	$ka->uid = $node->uid;
	profile_load_profile($ka);

When I want to get he person who is logged in I use:

global $user;   and $user->uid ;

I suppose you after the last one.

Harjoituspäiväkirja - www.lenkkivihko.fi

nevets’s picture

Most people override theme_user_profile something like this

<?php
/**
* Catch the theme_profile_profile function, and redirect through the template api
*/
function phptemplate_user_profile($user, $fields = array()) {
  // Pass to phptemplate, including translating the parameters to an associative array. The element names are the names that the variables
  // will be assigned within your template.
  /* potential need for other code to extract field info */
return _phptemplate_callback('user_profile', array('user' => $user, 'fields' => $fields));
  }
?>

and the part that reads 'user' => $user makes the variable $user available as $user in user_profile_tpl.php which means the global $user is hidden. If you need both change 'user' => $user to 'account' => $user, then in user_profile.tpl.php change all uses of $user to $account. Then you can declare $user as global and reference data about the person logged in (using $user).

rainer_f’s picture

Maybe a little to late for the party...

but simply use $_GLOBALS['user'] when your "global $user" is hidden!

konst.vinogradov’s picture

is it possible to use this way in snippet?

crc5002’s picture

Actually, $GLOBALS['user']

gbstack’s picture

In profile page, you can use $user->uid directly. And in other pages, $user is defined as a global variable. This post explains how to get user id in drupal: drupal get user id