External page - getting user's ID and details?

Ingenious

Well-known member
On my vB forum I allow access to a specialist forum if the member "signs" a disclaimer. This disclaimer is just a form on an external page. However it was easy to add some lines of code to the start of that external page, so that it would check if the user was logged into vB, and if so, pre-fill their username into the disclaimer for emailing to me (or tell them to log in first, or detect if they were already in the upgraded usergroup and send them packing).

Code:
require_once('global.php');

(this loaded up the vB session etc)

and later on:

<? if ($vbulletin->userinfo['userid']!=0) {
(user is logged in)

if (is_member_of($vbulletin->userinfo, 10)){

(tell user they are already in that usergroup0

}

}else{
tell user to log in}

You get the idea :)

Is there a XenForo equivalent of this please?

I need to check:
Are they logged in?
If logged in, are they already in the target usergroup?
If logged in and not already in the target usergroup, get their username to pre-fill a form for them to submit.

A copy and paste example would be great :)

Thanks.
 
Brilliant - many thanks (was sure it must have been asked for but didn't know what to search for).

Just a few questions.

To get the user's username then I can use

Code:
$username = $visitor->get('username');

Is that right?

How would I check to see if they are a member of usergroup 9?

And last question, how would I checked if they are even logged in? Would this code:

Code:
$user_id = $visitor->getUserId();

Be a value of 0 if they are not logged in?

Ta :)
 
PHP:
  $visitor = XenForo_Visitor::getInstance();
        $userName = $visitor['username'];
        if ($visitor->isMemberOf(3)){
            //user is member of group 3
        }
 
if (!$visitor->getUserId()){
//user is not logged in

It's not working for me, I got 0 for the user_id for example.
 
Top Bottom