1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

External page - getting user's ID and details?

Discussion in 'XenForo Questions and Support' started by Ingenious, Aug 9, 2011.

  1. Ingenious

    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.
     
  2. ragtek

    ragtek Guest

  3. Ingenious

    Ingenious Well-Known Member

    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 :)
     
  4. ragtek

    ragtek Guest

    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
     
    nothingatall and Ingenious like this.
  5. Ingenious

    Ingenious Well-Known Member

    Many thanks ragtek :)
     
  6. account8226

    account8226 Guest

    It's not working for me, I got 0 for the user_id for example.
     
  7. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

Share This Page