MyBB Community Forums

Full Version: what is IN_MYBB and how it works?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a javascript authoring front end I have designed for some added myBB mod I am developing, and it accesses a php script I wrote to return some custom values from the database.

at the top of my php file, I have the following code, but I am not sure if they are needed or what they are for. (not sure why I put them there, except I was copying what is at the top the other mybb php files such as showthread.php.

define("IN_MYBB", 1);
define('THIS_SCRIPT', 'structForums.php');

what do these two lines do, and do I need them in the php file that my javascript is addressing through AJAX?

Thanks for any help!

Gordon
IN_MYBB - If you look at the top of inc/init.php, all this does is acts as a key more or less to utilizing the functions within init.php. From what I understand if you don't define it, you won't be able to use init.php's (anbd perhaps other files) functions, which is what drives MyBB.
THIS_SCRIPT - I'm not 100% sure but I believe it just tells other core MyBB files what the filename is for referencing purposes.
This is for security.
Wow, thanks for your answers.

How's it for security - how does that work?

so, I need to have both lines at the top of my code?

what about the places in the code where you see:

if( ! defined( "IN_MYBB" ){

It doesn't make sense to have that check and the other two lines in the same file, does it?
I am not calling the functions in this php page, "structForums.php" anywhere but from AJAX.
If IN_MYBB macro isn't defined most of the MyBB files will dump you out, because they disallow direct access. Defining it and then checking to see if its defined in the same file is pointless though. For example you WANT the check in a plugin file because you don't ever want a plugin to be accessed directly. You only want it defined in php scripts you want accessed directly, and you want it defined BEFORE require_once() on global.php so that you can access all of the MyBB functions/vars ($mybb, $db, etc...) so yes that should be there.