Jump to content
TNG Community

Login/logout text switching...


beun.net

Recommended Posts

On my index-page I use this code to display either LOGIN when one is not logged in, or LOGOUT, when one is logged in:

<?php
        if( $currentuser ) {
            echo "<b><a href=\"logout.php\" class=\"menured\">$text[mnulogout]</font></a></b>\n";
        }
        else {
            echo "<b><a href=\"login.php\" class=\"menured\">$text[mnulogon]</font></a></b>\n";
        }
?>

This works the way it should. No problems there.

Now I have pasted this code into the file topmenu.php, so it will also show up in my topmenu at every other page.

Can anybody tell me why on topmenu.php the login/logout text does not change when one is logged in or out, while with this exact same code, it does change on the mainpage?

It keeps saying "Login", even though one is already logged in.

(I've removed it from topmenu.php for now, since it doesn't work)

Link to comment
Share on other sites

Can anybody tell me why on topmenu.php the login/logout text does not change when one is logged in or out, while with this exact same code, it does change on the mainpage?

It keeps saying "Login", even though one is already logged in.

Because topmenu.php is called inside the function tng_header in genlib.php and the scope of the variable $currentuser does not extend into that function.

In order to get it to work you need to add

global $currentuser;

right after the other global declaration in the tng_header function.

See my previous reply on this subject under the section labeled "Long answer".

Link to comment
Share on other sites

Because topmenu.php is called inside the function tng_header in genlib.php and the scope of the variable $currentuser does not extend into that function.

In order to get it to work you need to add

global $currentuser;
right after the other global declaration in the tng_header function. See my previous reply on this subject under the section labeled "Long answer".
Yay, wohoo :grin: Adding the
global $currentuser;

did the trick.

Thanks.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...