Not Solved Is there anyway to pull the user's username to use outside the /forums/ directory
#4
Not Solved
(2016-12-01, 12:10 AM)contrad2 Wrote:
(2016-11-30, 09:01 PM)dragonexpert Wrote: What you will need to do is include the global.php file from the directory your forum is installed in.  Do note that you will need to define the constant IN_MYBB as the value 1 or it will give you an error.

<?php
define("IN_MYBB", 1);
require_once "path_to_global.php";
if($mybb->user['uid']) {
$_SESSION['username'] = $mybb->user['username'];
}
else {
// Not logged in user.
}


Thanks for the reply. It's not setting the session, even if I'm currently logged into the forums. Does this need to be executed from a myBB template of some kind? I currently have it in it's own php block on a separate page. It's executing the code as the else result is firing, but the session isn't being set.

This does not utilize the template system. Did you adjust,
require_once "path_to_global.php";
to include the actual path?

Something like,
<?php
define("IN_MYBB", 1);
require_once "./forums/global.php";
if($mybb->user['uid']) {
$_SESSION['username'] = $mybb->user['username'];
}
else {
// Not logged in user.
} 
might be a better example for someone less experienced in PHP.

Please let us know the exact code you are using to set the session and please let us know if you are logged into mybb at the time.
Software Engineer specializing in C# Program Development
Reply


Messages In This Thread
RE: Is there anyway to pull the user's username to use outside the /forums/ directory - by Lunorian - 2016-12-01, 02:52 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)