XenForo Tutorials

Get user_id of visitor

Submitted by Yondu, , Thread ID: 197748

12-02-2021, 08:55 PM
#1
In XenForo 1, getting the user_id involved the getInstance and getUserId methods.

Code:
$user_id =XenForo_Visitor::getInstance()->getUserId();
In XenForo 2, it's a matter of using visitor().

Code:
$visitor = \XF::visitor();

$user_id = $visitor['user_id'];

Once the user_id is known then the $user information is available.

Code:
$finder = \XF::finder('XF:User');
$user = $finder->where('user_id', 1)->fetchOne();

\XF::dump($user);
[Image: wsUuw16j6oyxLLRnnK.gif]

Users browsing this thread: 1 Guest(s)