No announcement yet.

Use vBulletin API to confirm if a member is in a usergroup?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Use vBulletin API to confirm if a member is in a usergroup?

    I have a forum running vBulletin 4.2.0 PL2 (soon to be upgraded to 4.2.5). On another domain, I want to customise offerings to users based on their membership of a particular usergroup on the forum. So, on the non-vBulletin site (also PHP), they give their forum username and then, ideally, an automatic check between sites is done to customise what's offered.

    Basically, can I use the vBulletin API to pass a username to it, and get a "yes" or "no" if the given user is in (as either primary or additional) usergroup with ID 15?

    I thought this would be quite a basic request and perhaps done before but I can't find any help on it, anywhere.

    If not using the API, perhaps using a custom script as long as it's locked down (e.g. only allowed from certain referrers)? But I'm not sure how to go about that, either!

    Any help much appreciated.

  • #2
    The user's usergroups are returned from the /includes/api/6/member.php file. You can review that class to see its methods.

    If both domains are on the same server and both have access to the database, you can probably make a direct query to the user table in the vBulletin database to get the information as well.
    Translations provided by Google.

    Wayne Luke
    The Rabid Badger - a vBulletin Cloud demonstration site.
    vBulletin 5 API - Full / Mobile
    Vote for your favorite feature requests and the bugs you want to see fixed.


    • #3
      Thanks, I've just had a quick look in /includes/api/6/member.php and, while that might be the right place to start, I must admit it puts me no further forward on the "using the API" front!.

      Both domains are on the same server but security limitations mean they can't access each other's databases, unfortunately.

      I ended up very quickly coding a PHP file called checkgroups.php in the forum's folder: -

      PHP Code:

      if (!isset(
      $_GET['email'])) {
      die (
      'No Email');

      if (!
      filter_var($_GET['email'], FILTER_VALIDATE_EMAIL)) {
      die (
      'Invalid Email Address');

      $mysqli=new mysqli($config['MasterServer']['servername'], $config['MasterServer']['username'], $config['MasterServer']['password'], $config['Database']['dbname']);

      // make safe email just in case
      $email mysqli_real_escape_string($mysqli$_GET['email']);

      $query "SELECT usergroupid, membergroupids FROM forum_user WHERE email = ?";
      if (
      $stmt $mysqli->prepare($query)) {


      $groups = array();

      // add the main usergroup ID, usually always set
      if ($usergroupid != '') {

      // now add any additional usergroups
      if ($membergroupids != '') {
      $extragroups = array();
      $extragroups explode(','$membergroupids);

      $groups array_merge($groups$extragroups);

      if (
      in_array("15"$groups)) {
      die (
      } else {
      die (

      This is called using cURL from the other domain, passing the email address (which is common between the two sites): -

      PHP Code:
      // Get cURL resource
      $curl curl_init();
      // Set some options - we are passing in a useragent too here
      curl_setopt_array($curl, [
      CURLOPT_URL => '' $userEmail,
      CURLOPT_USERAGENT => 'Non Forum Site cURL Request'
      // Send the request & save response to $resp
      $targetGroup curl_exec($curl);
      // Close request to clear up some resources

      The script at the forum returns a 0 or 1 depending on if the given email has group #15 in either their main or additional groups. That 0 or 1 is in the $targetGroup variable on the non-forum site.

      It seems to work - can you see any issues with this approach / script?


      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.