MyBB Community Forums

Full Version: Cannot access Global.php
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I am trying to get the current username. I am logged in, however, when I use this code:

define('IN_MYBB', 1);
        require_once "./forums/global.php";
        
        $username = $mybb->user['username'];

$username is empty.

I have no errors and the file is working because when I load my forums, its all fine.

Anyone have an idea why it isn't working? I've tried this code:

global $mybb;

above:

$username = $mybb->user['username'];

Also but still nothing?

EDIT: http://connectiongaming.net76.net/ is the page it is on and http://connectiongaming.net76.net/forums is where my forums are held.
(2015-10-10, 12:10 PM)Nineteh Wrote: [ -> ]Hello,

I am trying to get the current username. I am logged in, however, when I use this code:

define('IN_MYBB', 1);
        require_once "./forums/global.php";
        
        $username = $mybb->user['username'];

$username is empty.

I have no errors and the file is working because when I load my forums, its all fine.

Anyone have an idea why it isn't working? I've tried this code:

global $mybb;

above:

$username = $mybb->user['username'];

Also but still nothing?

EDIT: http://connectiongaming.net76.net/ is the page it is on and http://connectiongaming.net76.net/forums is where my forums are held.

Adjust your cookie settings, set "Cookie Path" to "/" instead of "/forums". You are running into this issue because the cookie isn't sent with the request. You will probably have to clear your cookies for this to take effect.
Will doing this effect the forums?
No.
(2015-10-10, 12:20 PM)Nineteh Wrote: [ -> ]Will doing this effect the forums?

No, it won't. The cookie path is there to make sure that in case of multiple MyBB instances under the same domain the cookies don't conflict.