MyBB Community Forums

Full Version: RE: MyBB and my Website Login integration ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

As is suggested by the title.
I am looking for a solution to run my Website Login and Mybb over the same Login.

Does anyone here have already made experiences with that and can help me?
Also other suggestions are very welcome.


Ok i have try it over a (SSO) Force Login but can not get it working.

That is my Login.php.


if ($page->isPostBack())
	if (!isset($_POST["username"]) || !isset($_POST["password"]))
		$page->smarty->assign('error', "Please enter your username and password.");
		$page->smarty->assign('username', $_POST["username"]);
		$users = new Users();
		$res = $users->getByUsername($_POST["username"]);
		$dis = $users->isDisabled($_POST["username"]);
		if (!$res)
			$res = $users->getByEmail($_POST["username"]);
		if ($res)
			if ($dis)
			$page->smarty->assign('error', "Your account has been disabled.");
			else if ($users->checkPassword($_POST["password"], $res["password"]))
				$rememberMe = (isset($_POST['rememberme']) && $_POST['rememberme'] == 'on') ? 1 : 0;
				$users->login($res["ID"], $_SERVER['REMOTE_ADDR'], $rememberMe);

				if (isset($_POST["redirect"]) && $_POST["redirect"] != "")
					header("Location: ".$_POST["redirect"]);
					header("Location: ".WWW_TOP.$page->site->home_link);
				$page->smarty->assign('error', "Incorrect username or password.");
			$page->smarty->assign('error', "Incorrect username or password.");

$page->smarty->assign('redirect', (isset($_GET['redirect'])) ? $_GET['redirect'] : '');
$page->meta_title = "Login";
$page->meta_keywords = "Login";
$page->meta_description = "Login";
$page->content = $page->smarty->fetch('login.tpl');

That is the php Code i integrated in the Login.php above.

define('IN_MYBB', 1);
// Modify path here for your needs:
require_once 'Forum/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);

     header( "Location: http://mysite/Forum/member.php?return=$return&status=hello" ) ; 
     header ("Content-Length: 0");

What do i wrong ?