MyBB Community Forums

Full Version: IN_MYBB not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
define("IN_MYBB", 1);
require("../forum/global.php"); // correct path
global $mybb;
        
echo "XXX" . $mybb->user['username'] . "XXX";

This was working with mybb 1.6 but now I've installed 1.8,14 and $mybb->user['uid'] etc don't return anything, user is logged on, tried multiple browsers, multuple user login's

thanks zed
You don't need to make $mybb global if it is used in the global scope (ie. after requiring global.php in the global scope).

To your question, your code works fine for me:

[Image: 0d181530-cbca-41cc-b959-23f333aa69fe.png]

Are you absolutely certain that there is no conflict with the require path? If your PHP file is in the same folder as global.php then you would not need to preface it with "../"

Try:

define("IN_MYBB", 1);
require("global.php");

echo "XXX" . $mybb->user['username'] . "XXX";
OK thanks Wildcard, removed the 'global $mybb;'

but it's still not working

define("IN_MYBB", 1);
require("../forum/globalTEST.php");

[01-Feb-2018 20:48:57 UTC] PHP Warning:  require(../forum/globalTEST.php): failed to open stream: No such file or directory in /home/zedzeek/public_html/hb/movies/title.php on line 145
[01-Feb-2018 20:48:57 UTC] PHP Fatal error:  require(): Failed opening required '../forum/globalTEST.php' (include_path='.:/opt/alt/php71/usr/share/pear') in /home/zedzeek/public_html/hb/movies/title.php on line 145

define("IN_MYBB", 1);
require("../forum/global.php");


gives no error's thus the path is correct

$mybb->user[ whatever ] 
is just not returning anything, is there perhaps something I need to turn on in the mybb config?
define( 'IN_MYBB', 1 );
require_once './global.php';

echo "XXX" . $mybb->user['username'] . "XXX";

should work fine.
(2018-02-01, 10:43 PM)Sazze Wrote: [ -> ]
define( 'IN_MYBB', 1 );
require_once './global.php';

echo "XXX" . $mybb->user['username'] . "XXX";

should work fine.

cheers I'll try that later (I have to go to work now) though don't see it making a difference, it finds the global file or else it would give an error otherwise
for a laugh I installed phpbb to see if that works, and had no issues

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.'.$phpEx);
$user->session_begin();
echo "hhh" . $user->data['user_id'] . "HHH";

perhaps its the new version of mybb, I will uninstall and try an older version
What your problem is is that you probably are not using the correct path to global.php as I have created many custom pages and have not encountered this issue.
(2018-02-01, 11:28 PM)dragonexpert Wrote: [ -> ]What your problem is is that you probably are not using the correct path to global.php as I have created many custom pages and have not encountered this issue.

How can I use the correct path?
Test Case

If you read the reply's (my posts) you will see its finding a global.php file
perhaps its finding some other file called the same ( unlikely, but still has mybb changed so much from 1.6 -> 1.8 )
$mybb->user[ whatever ]

That won't return anything as it isn't the correct code. You need to put it in quote marks:

$mybb->user["whatever"]
What URLs are you accessing this on? It might not even see you as being logged in, which is why it doesn't display any user information.
(2018-02-02, 04:20 AM)Ben Cousins Wrote: [ -> ]
$mybb->user[ whatever ]

That won't return anything as it isn't the correct code. You need to put it in quote marks:

$mybb->user["whatever"]
Sorry yeah that looks like I'm typing the wrong thing, but I'm doing the correct syntax see my first post. I was using whatever as in "uid" "username" etc


(2018-02-02, 12:13 PM)Matt Wrote: [ -> ]What URLs are you accessing this on? It might not even see you as being logged in, which is why it doesn't display any user information.
Yes Im logged in "Welcome back, zedzeek. You last visited: Today, 08:51 PM
echo $mybb->user['uid']; == 0

Tried multiple times logging in/out etc, Its just not allowing me access to $mybb->user['username'] etc

I've installed 1.8.10 and 1.8.12 both have the same issue, I will try 1.6.X next

edit: actually I'll try 1.8.11 as this is what I had previously installed and that worked (it's what I've been using for the last year)

I'm starting to lose patience, this should not be this difficult
As you can see I've installed 1.8.11 and are logged in, yet if I try to click on anything it asks for login details again, but doesnt log in, stuck in an unending loop.
Something to do with cookies I suspect[Image: mybb1.png]
Pages: 1 2