MyBB Community Forums

Full Version: Check if user is logged in
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys, I'm not sure this is the appropriate board, but, try to help anyway.Blush

I just followed the tutorial here: http://community.mybboard.net/thread-13430.html
I don't know PHP, so I don't know how to check whether a user is logged in or not on each page. Can someone show me how?Big Grin
If you've required global.php in your PHP code, then you can use:
if($mybb->user['uid'])
{
 //user is logged in
}
else
{
  //user is not logged in
}
(2008-10-24, 07:35 PM)DennisTT Wrote: [ -> ]If you've required global.php in your PHP code, then you can use:
if($mybb->user['uid'])
{
 //user is logged in
}
else
{
  //user is not logged in
}

I'm planning on writing an external application that uses mybb for authentication, will including global.php still work in this instance?
Of course. Wink
This doesn't work.

It works if the user is logged in, however if you logout it doesn't clear the user['uid']. At least not in the application set up I have.

I just cleared my cookies and it removed the uid from the area.

Is this how it is intended to work?

Not that I have an issue with the cookie remaining but if someone is viewing the site on another computer not their own and logs out but doesn't close the browser and leaves it open then this is a potential problem is it not?

For my testing purposes clearing cookies is fine but is this something that should happen?
I've had an issue with MyBB occasionally not removing cookies by itself. Every so often, logging out fails completely, and I have to go clear cookies. Next time this happens, go to the forum, and see if it still says you are logged in.
I wasn't. Well I went back to the forum and saw I was logged out I didn't refresh it however to make sure I've seen what you've explained happen before as well.
I just checked. I am logged into my account, but my husband's account which I was testing plugin functionality for was still logged in and it was still being show on the addditional page using this particular technique to check user logged in.

Are there any suggestions on how to fix this? This is a big bug In My Opinion.
With cookies, you have to make sure the path/domain is set up right. If your external script has a different path to that set up for the forum, things get a little problematic.
I have my forum on a subdomain of my site, but the cookies have to work in the site as well. I followed the instructions of the Admin cp.
Quote:The domain which cookies should be set to. . .It should also start with a . so it covers all subdomains.
So the domain for cookies is .SITE NAME.com.
The cookies sound right. By "log out" are you referring to the logout link at the top here? Does logging out work for you here?