MyBB Community Forums

Full Version: Displaying Current User
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How can i display a users name thats online on my forum and is currently viewing a certain webpage.

So for example my user is logged in on "www.mysite.com/index.php"

but when the user visits theis page "www.mysite.com/newpage" i want to be able to place some text on the "newpage" saying "Welcome: The username here"
Include global.php on the external page and use $mybb->user['username']
And how would i use it when ive placed global.php in the external pages folder?
echo $mybb->user['username'];

OFFTOPIC: Is this a PHP class (the $mybb-> bit)? Im looking to expand my php knowledge Toungue
(2010-04-12, 02:35 PM)dunlop03 Wrote: [ -> ]And how would i use it when ive placed global.php in the external pages folder?

If these pages aren't in the MyBB folder you'd just need to put the path to it.

include "forum/global.php"; // go up a folder
include "../global.php"; // go back a folder
include "../folder/global.php"; // go back a folder then into 'folder'

(2010-04-12, 03:06 PM)tommykent1210 Wrote: [ -> ]
echo $mybb->user['username'];

OFFTOPIC: Is this a PHP class (the $mybb-> bit)? Im looking to expand my php knowledge Toungue

Yes, there would have been this:

$mybb = new MyBB;

'MyBB' is the actual class, you then assign it to a variable to use.
Oh man lol, im lost. So what do i need to place in the "Index.php" of my new page ?
If we can have some sort of idea of your file structure we'll be able to give you the correct code. Where is this new page in relation to the forum folder??
In my root folder i have another folder "New page" and all its contents are in there , index.php etc

so my main url is www.mysite.com and my new page is www.mysite.com/newpage
This is what i used but it doesnt work.

<?php
include ("global.php");

echo $mybb->user['username']
?>