Check if user is logged in
#1
Question 
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
Reply
#2
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
}
Dennis Tsang
Former MyBB Team Member
Web: http://dennistt.net
Reply
#3
(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?
Reply
#4
Of course. Wink
Reply
#5
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?
Reply
#6
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.
Reply
#7
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.
Reply
#8
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.
Reply
#9
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.
Reply
#10
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?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)