Integrate MyBB forums with your website

denzil

New Member
Messages
134
Reaction score
3
Points
0
Hi! I recently had the need to integrate my myBB forums with my website (such as logins and other user info). I found this to be a short and elegant solution. I tested this in mybb version 1.6.1, and it worked on Chrome and IE 8. I believe it works in FF and Opera too. This is a php solution by the way.

Firstly, add this in your index page (make sure you add it before any other includes. It's a good idea to make it the first lines of code on your page):

<?php
chdir("mybb/");
define("IN_MYBB", 1);
include("./global.php");
chdir("../");
?>

Note, the directory change has to point to your forum's directory. My example forums are in the "mybb" directory in my public_html.

I also checked my adminCP on my forums. Go configuration, settings, general configuration.
Here you can check the following:
*Check that Cooke Domain is set to your correct domain, for example .myexample.x10.mx
*Cookie Path: /
*Cookie Prefix: I read to leave this blank.

Now you can access your user data from any page on your website:
$mybb->user['username'], will give you the username, of course.

Here are some other details you could access:
$mybb->user['uid'];
$mybb->user['remember'];
$mybb->usergroup['canviewprofiles'];
$mybb->user['usergroup'];
$mybb->user['language'];
$mybb->usergroup['cansendemail'];
$mybb->user['email'];
$mybb->user['logoutkey'];
$mybb->user['signature'];
$mybb->user['avatar'];
$mybb->user['pmnotice'];
$mybb->user['notepad'];
$mybb->user['totalpms'];
$mybb->user['birthdayprivacy'];
$mybb->user['hideemail'];
$mybb->user['usertitle'];
$mybb->user['birthday'];
$mybb->user['website'];
$mybb->user['msn'];
$mybb->user['yahoo'];
$mybb->user['icq'];
$mybb->user['aim'];

I believe these are all up to date and still work!

Here is an example of a login form that will display if the user is not logged in:
<?php
if(!$mybb->user['uid'])
{
echo "<form action='mybb/member.php' method='post'>";
echo "<input type='hidden' name='action' value='do_login' />";
echo "<input type='hidden' name='url' value='../index.php' />";
echo "Username: <input type='text' name='username' maxlength='30' /><br />";
echo "Password: <input type='password' name='password' /><br />";
echo "<input type='submit' name='submit' value='Login' />";
echo "</form>";
}
?>

Note: you should add the global.php includes as described as well in any file that you wish to access the $mybb object.

You can make it static of course, but I'm not going to do that here. Hope someone finds this useful!
 
Last edited:

callumh98412

New Member
Messages
15
Reaction score
0
Points
0
What's the code for when the user is logged in? Private message it to me :)
 
Last edited:
Top