Matt Talley
Matt Talley

Reputation: 27

Getting the user's username - MyBB

I was wondering how I would go about getting the user's username. What i want to do is display it like this:
<a href="{$mybb->settings['bburl']}/usercp.php?action=profile">Username here</a>
I tried this:
{$mybb->user['name']}'
But that was unsuccessful and I cannot seem to find anything on Google.

Thanks for any help!

Upvotes: 0

Views: 7401

Answers (3)

Toan Nguyen
Toan Nguyen

Reputation: 936

Try to put this one into your template.

{$mybb->user['username']}

No need to use PHP for an existed variable.

Upvotes: 2

David Refoua
David Refoua

Reputation: 3617

And you can combine all like this, i think.

<?php
define("IN_MYBB", 1);
require ('global.php'); // be sure that u r running this php-code in the same
                        // directory of global.php, or else change the path.
if($mybb->user['uid'] > 0)
{
    $uid  = $mybb->user['uid'];
    $user = get_user($uid);
    $name = $user['username'];
}
    // custom else here: in case of not logged-in user
?>
<a href="{$mybb->settings['bburl']}/usercp.php?action=profile"><?echo $name?></a>

Upvotes: 2

Harry
Harry

Reputation: 735

I am not that experienced with MyBB but after some research i found a few different ways.

$user = get_user($uid);
echo $user['username'];

or

global $db;
$qry = $db->query("SELECT uid FROM ".TABLE_PREFIX."users WHERE username = '".$usernamevar."'"); 

Upvotes: 5

Related Questions