How can I hide some blocks for unauthorized users? I need to have some "private" block, that are displayed only for logged (authorized) users. Thanks.

Comments

patrickharris’s picture

This code will check if someone is logged in:

global $user;
if ( $user->uid ) {
  // user is logged in
}
jmkollar’s picture

I'm new to Drupal. Probably it's my fault, but I don't know what to do with that code. What I need is following:

If someone looks on the drupal site "www.example.org" he will see some public links... (as anonymous user). Than if he creates an account and logs in with name and password, he will see also some other blocks (menu items on the left side). I don't know how to configure blocks in Drupal to be visible only for logged users. That's it.

patrickharris’s picture

Are you using Drupal 4.6? Try Drupal 4.7 beta-2. When creating blocks with Drupal 4.7, you can choose to only display the block if some php code returns true. It's in the "Page specific visibility settings" when you edit the block. You choose the option "Show if the following PHP code returns TRUE" and add the php code to the box.

ica’s picture

-imo- It could be better if dropdown option of groups/roles/users
given without or optional to the use of the code above...
i.e
this block visible/invisible to
x [editors] (or any other groups, that you set on roles section of Drupal)
x [registered users]
x [public]
x [user ID/name]

it would make usability better!...
guess its not the Drupal way for some reason :)

- Just like in real life -if you like the overall 'package' of someone/something accept his/her/its shortcomings ;)

jmkollar’s picture

Thank you for your help. This is just what I wanted.

mamta sahu’s picture

I Have 3 role and i want to show blocks for specific roles only....how can i do this...

ludo1960’s picture

Easy http://drupal.org/node/64135 ! Go for it!!!