MyBB Community Forums

Full Version: How do I get a register/logout link?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Basically, on the top menu I want a plain link to 'register' and 'logout', but I only want each to appear (both in different place) when they should. So register only appears for logged out people, and logout obviously only appears for logged in users.

I tried using $logoutlink, but that doesn't seem to work globally, so I can't use it in my header template for the top menu. Putting it in the welcome area is one way of doing it, but I'd like it to be on the navmenu too since that's how most other forums go about it -- predictability is good.

Thanks for any help!
Add this to global.php, at the bottom right before the ?>:
if(!$mybb->user['uid']) {
$loginlogoutcustom = "<a href=\"$settings[bburl]/member.php?action=register\">".$lang->welcome_register."</a>";
}
else {
$loginlogoutcustom = "<a href=\"$settings[bburl]/member.php?action=logout&amp;uid=$mybbuser[uid]\">".$lang->welcome_logout."</a>";
}

Then in your header, add the $loginlogoutcustom variable.

The HTML is probably in the wrong format for the top menu, so customize to suit your theme.
Thanks! It didn't seem to work when I put it at the bottom of globals.php when I tried to include the variable in the header template, but it did if I included it at the top of the page right below the <body>. Not sure why that was, but moving the code in globals.php up to line 176 seemed to fix it.

Works a treat now.
Right, I forgot about that because the header gets parsed in the middle of global.php (doh stupid me)