Display for logged in users
Last modified: July 24, 2007 - 02:47
The following code will return TRUE for logged in users.
<?php
global $user;
return (bool) $user->uid;
?>To use this to only show to users that are NOT logged in you need to add an exclamation point (!) like so:
<?php
global $user;
return (bool) !$user->uid;
?>This check is no longer necessary in Drupal 5.x + since the block settings let you select who may view the block by role with check boxes.

I used this snippet not in
I used this snippet not in the block visibility field but in a node template, to display content only to logged-in, authenticated users. It worked fine until I installed the LoginToboggan module, which creates an intermediate "unvalidated user" role.
Here is a revised snippet that will display content only to authenticated users.
<?phpglobal $user;
$denied_voting_roles = array('anonymous user', 'unvalidated user');
if (is_array($user->roles)):
if (count(array_intersect($user->roles, $denied_voting_roles)) == 0):
// display content to authenticated users
else:
// do not display content otherwise
endif;
endif;
?>