Most of this code is originally from MyBB 1.4, but does work in 1.6
Please note: I'm not an expert on avoiding conflicts with your other script. I use this code with SSL and encrypted tokens, and those subjects are beyond the purpose of this tutorial.
#
Edit:
##
Feel free to ask questions, but sometimes my answer might be "it works figure it out".
- 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 '
Please note: I'm not an expert on avoiding conflicts with your other script. I use this code with SSL and encrypted tokens, and those subjects are beyond the purpose of this tutorial.
// !! 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;
#
Edit:
- This (above) shows SSO Integration (Single-Sign-On), but doesn't cover integration (syncing) of both user tables in your database.
- For basic use: You could have a small group of Admins/Editors who can log into your CMS (and this code gives them SSO into MyBB forum), while everyone else logs in normally to your forum.
- For advanced applications: Anyone with a matching username in "YourCMS" can instantly login to your MyBB forums.
##
Feel free to ask questions, but sometimes my answer might be "it works figure it out".
#
MyBB is the best forum software!
MyBB is the best forum software!