beun.net Posted September 14, 2006 Report Share Posted September 14, 2006 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) Quote Link to comment Share on other sites More sharing options...
rdmorss Posted September 15, 2006 Report Share Posted September 15, 2006 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 addglobal $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". Quote Link to comment Share on other sites More sharing options...
beun.net Posted September 15, 2006 Author Report Share Posted September 15, 2006 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 addglobal $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 Adding the global $currentuser; did the trick.Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.