Aug 29 2010

vBulletin Login Integration

I run a roleplaying chat website that has a forum and a separate chat section. However, the forum is integrated into the main site, and the chat. I was recently looking at moving from phpBB to vBulletin as the forum software[1], but needed to make sure that I could still plug the chat and the rest of the site into that easily. Apparently the vBulletin people are paranoid about giving out any code that is in any way related to vBulletin, even this sort of thing. So I did some digging, and found out how to do it.

Here's an example of how to do that. It really is pretty simple.

<?php
// This gets the vBulletin user login info
$curdir = getcwd();
chdir('/path/to/your/forums');  // Change to vBulletin directory
require_once('/path/to/your/forums/global.php');
chdir($curdir);  // Change back to previous directory

// This is the part that actually deals with users
if ($vbulletin->userinfo['userid'] == 0) {
  // User is not logged in; maybe show login form here
  echo "Not logged in.";
} else {
  // User is logged in
  echo "Welcome Back, <b>".$vbulletin->userinfo['username']."</b>";
  // See if user is in a certain user group
  if ($vbulletin->userinfo['usergroupid'] == '6' ) {
  // Maybe this is an admin usergroup, so show admin stuff here
  }
}
?>

So I hope someone else out there finds this useful. If you want to see what all data is contained in $vbulletin->userinfo, just do echo nl2br(print_r($vbulletin->userinfo, true)).

Caveat: I have yet to try this myself, so I'm not 100% sure it will work. But it seems to make sense, and is similar to integration of phpBB and SMF.

[1] Why move from phpBB to vBulletin, when vBulletin costs nearly $200? Overall vBulletin is just better, but here are a few more specific reasons, in order of importance:

  • vBulletin supports Facebook Connect out of the box. That means users don't have to sign up for an account on the forum — they can just click the Facebook Connect button, click to verify, and then bam… they have an account and they're logged in.
  • vBulletin has better anti-spam controls. My forum gets hit with more spam than regular posts. The best anti-spam measure is to require that new users pass a reCAPTCHA test. Modules that make phpBB do this are buggy at best. Granted, SMF (which is free) also has a module that does this pretty easily. It does not, as far as I can tell, currently have a working module for this. The best contender that I found costs $20, and seemed to have a broken implementation on their own site. Not very heartening.
  • vBulletin has a better plugin system. It's nowhere near as awesome as that of WordPress, but still much better than the "send file to server via FTP, edit your existing files" method of phpBB. Granted, a lot of the vBulletin community still does modifications in the old hack-ish way. SMF has a similar system to vBulletin. So as you can see, if it weren't for the damn Facebook Connect thing, SMF would probably win out. It's possible that between now and when I get around to this, the SMF mod will be working though.
  • vBulletin is neater. It's just got a lot more AJAX stuff, a WYSIWYG editor, and other little features that add up to making it a nicer overall experience.