I am using D7 and views for one of my projects. I have created a view that displays the name, age, role and orders of the user. I would like these things to displayed only for the logged in user. For instance user/1 should get his name,age,role and orders only, he should not be able to see the other's details. Similarly each and every user must be able to see their own details. I know i can use the uid from the url, but not sure how to achieve this.


2 Answers 2


You want the global variable $user...


Then the user_load() function...


  • Is there any way that i can use this in the views instead of coding?
    – user4081
    Jul 2, 2012 at 12:41
  • You can add a relationship of the current logged in user to your view. This should help: stackoverflow.com/a/10440513/1266251
    – Alex Gill
    Jul 2, 2012 at 12:47

Create a custom module and add following function.

function login_user_fn(){
   global $user;
   $fid = $user->picture;
   $file = file_load($fid);
    if($file !=''){

    $user_pic  = theme('user_picture', array('account' => $user , 'path' => $file->uri,));

    return ('Hello '.$user->name.'<br/>'.$user_pic);

And than call custom function " login_user_fn()" in our drupal custom block body.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.