• Welcome to Tux Reports: Where Penguins Fly. We hope you find the topics varied, interesting, and worthy of your time. Please become a member and join in the discussions.
Get user_id of visitor in XenForo 2

XenForo 2 Get user_id of visitor in XenForo 2

LPH

Flight Director
Flight Instructor
LPH submitted a new resource:

Get user_id of visitor in XenForo 2 - 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', 1)->fetchOne();

\XF::dump($user);

Read more about this resource...
 
Top