How can I know the UID of my user.

ivanux - December 11, 2007 - 14:46

I mean...
If I log with the user with the UID 2, if I check $user->uid I receive my UID... but if I check the Profile of the User with the UID 8 then $user->uid is 8 ...

What I need is the variable of MY UID then I can do things as:

if ($user->uid == $VARIABLE_OF_MY_UID) {echo "You can't add yourself in your buddy list"}
else {echo "Do you want to add " . $user->name . " to your buddy list?";}
...

Sorry for my english.
Regards.

In the profile pagetemplate

johsw - December 11, 2007 - 16:10

In the profile pagetemplate try adding a global $user; before you evaluate $user->uid

Best,
/Johs

Quick tip

nedjo - December 11, 2007 - 16:17

Say you're viewing a user's profile at user/21.

<?php
// Reference the current user.
global $user;

// Test the current path.
if (arg(0) == 'user' && is_numeric(arg(1))) {
 
// Test if this is the current user's profile.
 
if (arg(1) == $user->uid) {
    ...
  }
 
// If not...
 
else {
   
// Load the user account being viewed.
   
$account = user_load(array('uid' => arg(1)));
    ...
  }
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.