View Full Version : Get logged in username
doc55
09-01-2019, 06:16 PM
I'm using the following script to get the userid for the logged in user.
require_once('/forum/includes/vb5/autoloader.php' );
vB5_Autoloader::register( '/forum' );
vB5_Frontend_Application::init( 'config.php' );
$vb_userid=vB::getUserContext()->fetchUserId();
How can I get the username for the logged in user?
The vB_User class at /core/vb/api/user.php has a fetchUserinfo method that will return the userinfo of the current session.
I can't test if this works but something like:
$userInfo = vB_Api::instance('user')->fetchUserinfo();
or
$userInfo = vB_User::fetchUserinfo();
and then read it by accessing the username array key of the $userInfo array.
doc55
09-02-2019, 02:50 PM
The vB_User class at /core/vb/api/user.php has a fetchUserinfo method that will return the userinfo of the current session.
I can't test if this works but something like:
$userInfo = vB_Api::instance('user')->fetchUserinfo();
or
$userInfo = vB_User::fetchUserinfo();
and then read it by accessing the username array key of the $userInfo array.
Perfect. Thanks a bunch.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.