MyBB Community Forums

Full Version: Using JavaScript to check if user is logged in?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm writing my own basic ad plugin, and would like to disable the ads if a user is logged in.

Is there a way I can use JavaScript to check if a user is logged on?

Or is there an 'if' statement I can use in the template editor?
e.g
if (user logged on) {
do javascript stuff;
}
In the headerinclude template, find:
	var saving_changes = '{$lang->saving_changes}';
After that line, add:
var mybbuid = {$mybb->user['uid']};

Then in your JavaScript (code must be located below the headerinclude template), you can use
if(mybbuid)
{
    // user is logged in
}
else
{
    // user is not logged in
}
Bravo! Works perfectly, thanks Smile

I'm liking MyBB more and more everyday.