Well, I added this code to the top of my header file:
<?php
define('IN_MYBB', 1); // (1a)
require "./forum/global.php";
?>
And, it works, sorta.
If I type something like {$mybb->user['username']}, it shows nothing.
However, if I put the same file into the /forum directory and change the code above to:
<?php
define('IN_MYBB', 1); // (1a)
require "./global.php";
?>
It'll work, and output the username, if there is one.
My question is, how would I fix this to work in the / directory so I don't have to move my files?
Also. . .
if(isset($mybb->user['username'])) {
echo $mybb->user['username'];
} else {
echo "Welcome Guest!";
}
This returns nothing.
Try this...
<?php
define('IN_MYBB', 1);
require "./global.php";
if($mybb->user['uid'])
{
echo $mybb->user['username'];
}
else
{
echo "Welcome Guest!";
}
?>
Displays welcome guest, but I'm logged in.
I think it's not able to communicate with the forum for some reason.
There must be something wrong with your setup because it works for me.
What path does your session cookie use (ACP > Settings > General Settings > Cookie Path?
here is what I add to my 'outside of mybb root' files that I want integrated
/**
* set the realtive path to your forums directory from where this scsript is (without trailing slash)
*/
$forumdir = "./board";
//end editing
define("IN_MYBB", 1);
if(substr($_SERVER['SCRIPT_NAME'],0,1) == "/")
{
define('THIS_SCRIPT', substr($_SERVER['SCRIPT_NAME'],1));
}
else
{
define('THIS_SCRIPT', $_SERVER['SCRIPT_NAME']);
}
$current_dir = getcwd();
//change working directory to allow board includes to work
$forumdirslash = $forumdir."/";
$change_dir = "./";
if(!@chdir($forumdir) && !empty($forumdir))
{
if(@is_dir($forumdir))
{
$change_dir = $forumdir;
}
else
{
die("\$forumdir is invalid!");
}
}
//include board files
require_once $change_dir."/global.php";
require_once MYBB_ROOT."inc/functions.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_user.php";
require_once MYBB_ROOT."inc/class_parser.php";
//change directory back to current where script is
@chdir($current_dir);
At the beginning of my file, doesn't output the username.
<?
/**
* set the realtive path to your forums directory from where this scsript is (without trailing slash)
*/
$forumdir = "./forum";
//end editing
define("IN_MYBB", 1);
if(substr($_SERVER['SCRIPT_NAME'],0,1) == "/")
{
define('THIS_SCRIPT', substr($_SERVER['SCRIPT_NAME'],1));
}
else
{
define('THIS_SCRIPT', $_SERVER['SCRIPT_NAME']);
}
$current_dir = getcwd();
//change working directory to allow board includes to work
$forumdirslash = $forumdir."/";
$change_dir = "./";
if(!@chdir($forumdir) && !empty($forumdir))
{
if(@is_dir($forumdir))
{
$change_dir = $forumdir;
}
else
{
die("\$forumdir is invalid!");
}
}
//include board files
require_once $change_dir."/global.php";
require_once MYBB_ROOT."inc/functions.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_user.php";
require_once MYBB_ROOT."inc/class_parser.php";
//change directory back to current where script is
@chdir($current_dir);
?>