I'm trying to find out how to check whether the current visitor is a logged in user or not. In any other file than node.tpl.php and comment.tpl.php I could easily use $user to check, but this object has got a whole other meaning in those two files. I wasn't able to find anything using Google, so I wondered if anyone here could enlighten me on this. Thanks in advance!

Comments

OSLinux’s picture

http://drupal.org/node/144735

User = role GUEST rid =1

http://drupal.org/node/92218

global $user;

if ( $user->uid ) {
  // Logged in user
}
else {
  // Not logged in
}

~~

Linux, Drupal5 and Simple Machines Forum R great (got a "non-Russian Bridge yet (for me..))
http://veberu.hostfabrica.ru/index.php

DRUPAL ME BAD!!! & Feel free to contact me (4 faster repsonse) I am happy to look at your site (privately or com

Xano’s picture

The global part did the trick. Hadn't thought of that. Thanks!

OSLinux’s picture

UR welcome ..

~~

Linux, Drupal5 and Simple Machines Forum R great (got a "non-Russian Bridge yet (for me..))
http://veberu.hostfabrica.ru/index.php

DRUPAL ME BAD!!! & Feel free to contact me (4 faster repsonse) I am happy to look at your site (privately or com

tallsimon’s picture

Thank you. This is useful, but I have looked through some of the core themes to look how it is implemented in them, and I can't see any code like that above in any of the template/theme files... does anyone know how they do it in the core themes....?

hychanhan’s picture

It is very useful information.

ChanHan Hy

tjjacobsen’s picture

Saved me a couple of hours of poking around in code. Thanks a ton!

albertski’s picture

You should use the variable $logged_in.

<?php if ($logged_in): ?>
<!-- logged in content here -->
<?php else: ?>
<!--  not logged in content -->
<?php endif; ?>