Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By rshad on
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
How I did it.
You forgot this:
global $user;
You can't call $user->uid without it.
Pobster
If you care about non clean URL support
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');