(2012-07-29, 02:46 PM)paranoiks Wrote: [ -> ]I have the following problem:
I have a site and a MyBB forum. In the site there is a login/registration form. How can I make this: when someone logs in the site to log him automatically in the forum? And also when someone registers in the site to automaatically register a user with the same usernam,email,password in the fourm?
Hi paranoiks,
To begin with, go visit
http://phpdave.com/MyBBIntegrator/, and download the constructor, this script has finished functions built upon the mybb core functions. You can easily use the constructor for login, logout and registrations.
As for the login function, here's a little bit of code that I use myself:
<?php
define('IN_MYBB', NULL);
global $mybb, $lang, $query, $db, $cache, $plugins, $displaygroupfields;
require_once '/path/to/mybb_forum/global.php';
require_once '/path/to/MyBBIntegrator.php';
$MyBBI = new MyBBIntegrator($mybb, $db, $cache, $plugins, $lang, $config);
$login_status = $MyBBI->login($_POST['username'], $_POST['password']);
if ($login_status == true) echo 'Logged in successfully';
else echo 'The login routine failed';
?>
Registration:
<?php
define('IN_MYBB', NULL);
global $mybb, $lang, $query, $db, $cache, $plugins, $displaygroupfields;
require_once '/path/to/mybb_forum/global.php';
require_once '/path/to/MyBBIntegrator.php';
$MyBBI = new MyBBIntegrator($mybb, $db, $cache, $plugins, $lang, $config);
$info = array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'password2' => $_POST['password_confirm'],
'email' => $_POST['email'],
'email2' => $_POST['email'],
'hideemail' => 1,
'allownotices' => 1,
'emailpmnotify' => 1,
'invisible' => 0,
'receivepms' => 1
);
$register_status = $MyBBI->register($info);
// Array means: registering failed
if (is_array($register_status))
{
echo implode('<br />', $register_status);
}
else
{
echo $register_status;
}
?>
Hope you found them helpful!