How to check if user is logged in in node.tpl.php and comment.tpl.php

Xano - July 28, 2007 - 07:30

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!

http://drupal.org/node/144735

OSLinux - July 28, 2007 - 09:28

http://drupal.org/node/144735

User = role GUEST rid =1

http://drupal.org/node/92218

<?php
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

The global part did the

Xano - July 28, 2007 - 14:11

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

UR welcome .. ~~ Linux,

OSLinux - August 7, 2007 - 12:21

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

how is it in core themes

tallsimon - November 24, 2009 - 22:16

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....?

Thanks,

hychanhan - April 3, 2009 - 07:33

It is very useful information.

ChanHan Hy

Cool...thanks!

tjjacobsen - September 9, 2009 - 00:45

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

 
 

Drupal is a registered trademark of Dries Buytaert.