MyBB Community Forums

Full Version: Integrating MyBB into your website. (Login Form)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
bk2070 Wrote:Okay heres a screen of what Im getting
If you look onto the right hand side you'll see the login box.

It's showing up like that because you did not format the code correctly. What it's supposed to do is when you are logged in it will show some friendly message, and when your logged out, it will show the login box so you can login.

If you dont want that message, then just use:

<?php
echo "
<form action='/forum/member.php' method='post'>
<input type=\"hidden\" name=\"my_post_key\" value=\"$mybb->post_code\" />
Username: <input type='text' name='username' size='25' maxlength='30' /><br />
Password: <input type='password' name='password' size='25' />
<input type='hidden' name='action' value='do_login'>
<input type='hidden' name='url' value='mypage.php' />
<input type='submit' class='submit' name='submit' value='Login' />
</form><br>";
?>

But make sure you place the following code on the page with the login form (the code above) BEFORE anything else on that page.

<?php
    define("IN_MYBB",1);
    chdir('forum'); // path to MyBB
    require './global.php';
?>
Black_Ice Wrote:Hi eRott,
Under your Admin CP go to Board Settings -> General Configuration. Set the following:

Cookie Domain = .mydomain.com
Cookie Path = /subfolder/

Note: This will allow the cookie to work for anything in the subfolder and below. As long as your log in script is in this folder or under, it should work.

Thank you =)
Any luck bk2070?
Perhaps you could give us the code for that section of your website. The php source code you have for that page, or even the code that is located around your login box.
whats the most up to date way to intergrate the mybboard login system with an existing website, i really cant read through those 24 pages.. Confused
it would help me out tonnes, thanks =]
At the moment the most up to date working solution as of 1.2.12 is here:
Black_Ice:

What are the forums board settings (General Configuration) that you're referencing?

Also - I'm trying to integrate MyBB into my site with top, left and right side borders intact. This requires me to implement MyBB inside an IFrame (see www.piccone.us). The problem is that when I click on some of the naviogation hyperlinks implemented by MyBB, the IFrame is shrunken to a size that is smaller than the MYBB page. Any ideas how to make this implementation work?

Any help would be appreciated. Thanks.

- John
Black_Ice Wrote:I've read all the pages here and it appears that the techniques here no longer work for MyBB. I've been doing some digging and analysing the MyBB form / code structure. Turns out there is a hidden field that has been added to MyBB's login form, probably added in 1.2.8 or higher. Anyway this field has allowed me to integrate my website and forum. Without further a do I will post my solution!

Checklist
If your website is located at mydomain.com and your forum at mydomain.com/forum then ensure that under your forums board settings (General Configuration) you set the following:

Cookie Domain = .mydomain.com (yes a leading dot!)
Cookie Path = /

The Code
Ensure the following code is put before EVERYTHING on your php webpage. Before <html> and before <head> etc.
<?php
	define("IN_MYBB",1);
	chdir('forum'); // path to MyBB
	require './global.php';
?>

Now the next bit of code will display one thing if logged in, if not it will display a login box.
<?php

if($mybb->user['uid'] > 0) { // The user is logged in, say Hi
	echo "Hey, ". $mybb->user['username'] .".<br>Thanks for logging in.<br><br>";

} else {

 	// The user is not logged in, Display the form
	echo "<form action='/forum/member.php' method='post'>
	<input type=\"hidden\" name=\"my_post_key\" value=\"$mybb->post_code\" />
	Username: <input type='text' name='username' size='25' maxlength='30' /><br />
	Password: <input type='password' name='password' size='25' />
	<input type='hidden' name='action' value='do_login'>
	<input type='hidden' name='url' value='mypage.php' />
	<input type='submit' class='submit' name='submit' value='Login' /></form><br>";
}

?>
Note: Replace mypage.php with the page you wish to go to after the log in

You'll notice the difference in this code compared to other's is the line in the form:
<input type=\"hidden\" name=\"my_post_key\" value=\"$mybb->post_code\" />
Without this logging in does not work.
Hope this helps. I'll try to help with any questions if anyone has any.

Regards,
Black Ice
@ jpiccone
When we say integration into a website most of us are trying to display a log in form on a page that is not the forum. This allows you to login to the site without having to visit the forum.
What you are trying to do is "literally" integrate the forum into your site, so I can see at your web address you are (like you said) trying to put the forum in a frame and retain the rest of the site's boarders and layout. If you're not trying to have a seperate log in form, for the forum then you need not worry about all the code that's been posted. The board settings won't apply to you either.

I don't have much experience with Iframes but the MyBB forum is a reasonable size so putting it inside a frame is going to cause it to not fit. To get around this you will either need:
1) Make your Iframe scroll
2) You could put the forum on it's own page without any frames, just have the forum the way it is and allow the main site to link to it. (I'd recommend this).

The forum has a completely different skin to your site so rather than trying to display both at the same time you could separate them and just link one to the other. You can add links to the forum's navigation bar that would link to the other pages of your site.

It's up to you but by integration we mean (in this thread) adding a seperate log in box to your site that logs you into the forums.

Regards,
Black Ice
With this way of logging in, is the users "input" cleaned from say SQL injections?

and my main question, once you login Via this form, and the user then clicks the fourms URL, will they be logged in?
and vice versa

Thanks.
To answer your question godsdead,
The input is clean from SQL injections because the page it is passed to (member.php) does all the "cleaning". The form just posts the inputs. Once you log in you can click any forum URL because you are logged in 100%, nothing dodgy. Yes vice versa works too.

The method works 100% and does log you in correctly.

Regards,
Black Ice
Okay, so this is the kind of thing I want to integrate onto my web page at http://rctlounge.com. However, whenever I try to put the code in, I get this error:
Warning: chdir() [function.chdir]: No such file or directory (errno 2) in /home/rctloung/public_html/index.php on line 3

Warning: require(./global.php) [function.require]: failed to open stream: No such file or directory in /home/rctloung/public_html/index.php on line 4

Fatal error: require() [function.require]: Failed opening required './global.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/rctloung/public_html/index.php on line 4
Can someone please clarify what I'm doing wrong? For now, it's not going to be included on the page.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48