Getting $user Information

Getting $user Information

LPH

Flight Director
Staff member
LPH submitted a new resource:

Getting $user Information - Get Visitor user_id

In XenForo 1, getting the user_id involved the getInstance and getUserId methods.

PHP:
$user_id =XenForo_Visitor::getInstance()->getUserId();

In XenForo 2, it's a matter of using visitor().

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

$user_id = $visitor['user_id'];

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

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

\XF::dump($user);

Read more about this resource...
 
Last edited:

LPH

Flight Director
Staff member
Made a slight change in the code to pull $user_id Instead of 1.
 
Top