MyBB Community Forums

Full Version: Let users authenticate on non-mybb pages
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How can I access a signed in user's data? I need name and post count. Nothing is stored in $_SESSION...
In your PHP file put this at the beginning:
define("IN_MYBB", 1);
require_once "global.php"; // Change this if the page is not in the same directory as forum.

After that, use $mybb->user['username'] and $mybb->user['postnum'].
Okay thanks a lot! However, I am not familiar with the OOP version of PHP. WOuld $mybb->user['username'] equate to $mybb = user['username']?

Anyone know?
(2015-03-21, 08:04 PM)MystByte Wrote: [ -> ]WOuld $mybb->user['username'] equate to $mybb = user['username']?

No. user is an array that's part of the $mybb object and you shouldn't change it (why would you do that anyways?).
(2015-03-21, 10:51 PM)Destroy666 Wrote: [ -> ]
(2015-03-21, 08:04 PM)MystByte Wrote: [ -> ]WOuld $mybb->user['username'] equate to $mybb = user['username']?

No. user is an array that's part of the $mybb object and you shouldn't change it (why would you do that anyways?).

So how would I write what dragonexpert wrote?

The way he wrote the code is weird... COuld someone translate that to regular PHP?
Signed in use'rs data, username and post count

<?php
define("IN_MYBB", 1);
require_once "global.php"; 
echo $mybb->user['username'];
echo $mybb->user['postnum'];

You can see all variables available as follows

<?php
define("IN_MYBB", 1);
require_once "global.php"; 
echo '<pre />';
print_r($mybb->user);
Ahh whatever. Thanks

For some reason, this doesn't echo the user's username:

if(isset($mybb->user['username'])){
       echo 'Welcome to the Trade Federation, ' . $mybb->user['username'];
   }

Never mind I fixed it. I had to move my program into the forum directory.