MyBB Community Forums

Full Version: best way to incorporate myBB into site with existing registration system?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone,

I'd like to add myBB to my site, but the user base is decidedly not tech savvy. I would like to avoid at all costs forcing people to register new usernames and passwords to use the forum.

I've spent about an hour browsing through the myBB code and off the top of my head I see two possible methods for integrating the two login systems:

1) When users log in to the site system, I create an additional cookie for myBB that tricks it into thinking this person is already logged-in. As the domain is the same this would probably work with a bit of tweaking.

2) I replicate the series of myBB login function calls within my own login script, thereby simultaneously logging the user into both systems in one pass.

(Both approaches assume I've already run a script to dupe all relevant registered user data from my existing user table into myBB's mybb_user table.)

Before I dive in, I'd be grateful if any veterans could provide some insight into which would be a better strategy... or suggest an entirely new one.

Thank you for your time.
what is the current system software your registrations are part of?
Hi Shaderach, Welcome to MyBB Smile

Most of this code is originally from MyBB 1.4, but does work in 1.6
  • You can use it to (force) login to MyBB as someone is logging into your other system/script/CMS, etc.
  • Works anywhere you are able to include ' mybb/global.php '

EZ Fast Login | (SSO Integration) | Force Login To MyBB

// !! Use w/ caution this logs a user in without a password
// auth is already done above
// You now have the MyBB username currently stored in  $name

define('IN_MYBB', 1);
// Modify path here for your needs:
require_once './global.php';  

$query = $db->simple_select("users", "uid,username,password,salt,loginkey,email,usergroup", "username='$name'", array('limit' => 1));
$user = $db->fetch_array($query);
my_setcookie('loginattempts', 1);
		$db->delete_query("sessions", "ip='".$db->escape_string($session->ipaddress)."' AND sid != '".$session->sid."'");
		$newsession = array(
			"uid" => $user['uid'],
		);
		$db->update_query("sessions", $newsession, "sid='".$session->sid."'");
		
		$db->update_query("users", array("loginattempts" => 1), "uid='{$user['uid']}'");
		
		// Temporarily set the cookie remember option for the login cookies
		$mybb->user['remember'] = $user['remember'];
	
		my_setcookie("mybbuser", $user['uid']."_".$user['loginkey'], null, true);
		my_setcookie("sid", $session->sid, -1, true);
	
        	$plugins->run_hooks("member_do_login_end");

// Modify below here for your needs:
      //  $user= $user['username'];
     header( "Location: enter_here.php?return=$return&status=hello" ) ; 
     header ("Content-Length: 0");
     exit;
(2012-05-17, 02:20 PM)pavemen Wrote: [ -> ]what is the current system software your registrations are part of?

Custom code in use at Panzer Grenadier Headquarters.

(2012-05-17, 03:15 PM)seeker Wrote: [ -> ]Hi Shaderach, Welcome to MyBB Smile

Most of this code is originally from MyBB 1.4, but does work in 1.6

*snip* *snip*

Outstanding, thank you. I'll write a script to sync the member tables and then give this a go. You've saved me a lot of time. I really appreciate it!
(2012-05-17, 10:38 PM)Shaderach Wrote: [ -> ]...
Outstanding, thank you. I'll write a script to sync the member tables and then give this a go. You've saved me a lot of time. I really appreciate it!

You are welcome.
Can't you just make the two script and myBB share the same DB?
(2012-05-19, 04:37 AM)Support Wrote: [ -> ]Can't you just make the two script and myBB share the same DB?

No, Yes, no...
...share the same DB is easy enough:

mybb tables can all start w/ mybb_
like mybb_users, mybb_posts, etc.
and then other_
like other_users

You might have wanted to say "share the same user table".
Try that with MyBB and Wordpress (for example), and see what happens. Toungue
(2012-05-19, 04:37 AM)Support Wrote: [ -> ]Can't you just make the two script and myBB share the same DB?

For security reasons I'd rather keep the two databases separate. That also allows me to easily drop myBB in the future, should I ever need to. That's unlikely, but loose coupling is almost always the best way to do your coding.
I have run into one sticking point - my total users statistic is not automatically updating. This makes me think I have neglected to include a stats-related trigger in my account creation code.

Anyone have an idea where I should be looking for that?
I have answered this already. It is a custom code base I wrote myself. I patched in a user account crosslink between my existing database and the myBB database. Whenever a user logs in it checks to see if they are in the myBB dbase as well. If they are not, they are inserted into mybb_users.

But it appears I have preempted a stats trigger because my "total users" stat is flat unless I do a manual recalculation in the Admin CP...