Submitted by Techdipu on Fri, 02/27/2009 - 15:39
The correct way of testing if a user is logged in is to test whether $user->uid is 0:
global $user;
if ($user->uid) {
$output = t('User is logged in!');
else {
$output = t('User is an anonymous user.');
}
This approach is often used when defining a block that shows one thing to
logged-in users and something else to anonymous users:
<?php
global $user;
if ($user->uid) {
return t('You are currently logged in!');
}
else {
return t('You are not currently logged in.');
}
?>
»
- Techdipu's blog
- 389 reads













Post new comment