I were working on drupal 7. In block configuration, under pages i went for an option "Pages on which this PHP code returns TRUE (experts only)"

Added the following code:

global $user;
   return TRUE;
  return FALSE;

It's shows me an error message at the top of the screen:

Notice: Undefined property: stdClass::$name in eval() (line 3 of C:\xampp\drupal77\modules\php\php.module(75) : eval()'d code).

I don't know, how to fix it out. Please help me out.Thanks

  • I tested the code you show, and it works for me.
    – apaderno
    Commented Oct 27, 2012 at 21:54

2 Answers 2


How the $username variable's value will be available there? If you want to use current logged in user, write it like global $user; and check $user->name instead of $username.


If I get you right you want to check for the admin user.

A possible code snippet would be:

global $user;
return $user->uid==1;

Of course you can check for any property of the $user object.

  • Hi, based upon user login...i needs to show the block (in sense return true or return false). Actual code, <?php global $user; $username=$user->user; checking with database, if count=1, returns true. Again am getting the same error. It's not solved.
    – jacksantho
    Commented Jun 29, 2012 at 6:33
  • The varialble $username is not defined in this context. All about the currently logged in user is in the global $user object.
    – BetaRide
    Commented Jun 29, 2012 at 7:06
  • hi thanks for your posting. See my error message "Undefined property: stdClass::$name" . The error message is not due to $username. please help me out.thanks
    – jacksantho
    Commented Jun 29, 2012 at 9:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.