I have a block of links, one of which is "Log In". I wish to change this to "Log Out" once the user, any user, is logged in. The easiest way I know to do this is to just have a little php code:


if (userLoggedIn) echo "Log_Out_link";
else echo "Log_In_Link";

Does such snippet of code exist? I tried searching the site but came up empty handed.

If there is a better way to do this, I would also like to know, but this way suits me just fine.

Comments

StevenPatz’s picture

if($user->uid) {
 echo 'click <a href="logout">here</a> to log off.';
}
pobster’s picture

global $user;

You can't call $user->uid without it.

Pobster

nevets’s picture

If you care about non clean URL support it is better to construct the link with the l function (thats a lower case L). The code to print a link would then look like print l(t('logout'), 'logout');