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
Is it useful only between PHP site?

I means main site made by JSP and forum mybb, is it can be use this tutorial?
Hello!
I'm using Wordpress and I want to put 'welcomeblock' template from MyBB to WP.

The structure of my site is:
Quote:domain.com - WP
forum.domain.com - MyBB

My cookies settings [MyBB] are:
Quote:Cooke Domain: .domain.com
Cookie Path: /
Cookie Prefix: (blank)

I edited header.php in Wordpress and added in the very first line the following code:
<?php
define("IN_MYBB", 1);
chdir("forum"); // path to MyBB
require "global.php";
?>

And what I get is:
 Fatal error: Cannot redeclare get_attachment_icon() in /home/user/domains/domain.com/public_html/forum/inc/functions.php on line 3071

What I did wrong? Confused
(2013-05-08, 02:29 AM)Adriano Wrote: [ -> ]Hello!
I'm using Wordpress and I want to put 'welcomeblock' template from MyBB to WP.

The structure of my site is:
Quote:domain.com - WP
forum.domain.com - MyBB

My cookies settings [MyBB] are:
Quote:Cooke Domain: .domain.com
Cookie Path: /
Cookie Prefix: (blank)

I edited header.php in Wordpress and added in the very first line the following code:
<?php
define("IN_MYBB", 1);
chdir("forum"); // path to MyBB
require "global.php";
?>

And what I get is:
 Fatal error: Cannot redeclare get_attachment_icon() in /home/user/domains/domain.com/public_html/forum/inc/functions.php on line 3071

What I did wrong? Confused

nothing it is a conflict between wp and mybb where they both have a function with the same name.

This is why I suggested all classes and functions in future builds of myBB be changed to be prepended with mybb_ which would totally alleviate such problems.

However that is a big task, and probably no feasible at this point.

You could try altering either mybb or wordpress to rename that function, if the function is identical in every way, then you could just remove the one in mybb
please help me i want to integrate my forum with joomla or wordpress please help me this i really looking for 1 month but i didn't get solution please help
Just want to give others a heads up on how to login on their own non-MyBB custom website (integration). While I did not script this myself (so I can't take credit and I can't remember where I got it from), I have modified a fair bit so that it works as it should and made it even more simpler than what it initially was.

First: You will not want to have your forums in the root of your website, so have them in a directory called "MyBB", "Forums", "Forum", or whatever you like, I'll refer to it as "forums" for now as that's how I've set mine.

Second: Set your "Cookie Path" (Admin -> Settings -> General Config) to "/" and have your "Cookie Prefix" set to nothing

Third: For your "index.php" file add this:
<?php
	global $rootpath;
	$rootpath = "/share/Web/public_html/";

	$forumpath = $rootpath . "forums/";
	
	chdir($forumpath);
	define("IN_MYBB", 1);
	require($forumpath . "global.php");
	require_once MYBB_ROOT."inc/class_parser.php";
	$parser = new postParser;
	chdir($rootpath);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>


<?php
	// Display if the user is logged in
	if ($mybb->user['uid']) {
?>
Welcome <a href="/forums/member.php?action=profile&uid=<?php echo $mybb->user["uid"]; ?>"><?php echo $mybb->user["username"]; ?></a>
<br />
<a href="/forums/member.php?action=logout&amp;<?php echo "logoutkey={$mybb->user['logoutkey']}"; ?>">Logout</a>
<?php
	} else { // If the user is not logged in then display the login form
?>
<form action="/forums/member.php" method="post">
	<input type="hidden" name="my_post_key" value="<?php echo $mybb->post_code; ?>" />
	Username: <input type="text" name="username" size="20" maxlength="30" /><br />
	Password: <input type="password" name="password" size="20" /><br />
	<input type="hidden" name="action" value="do_login" />
	<input type="hidden" name="url" value="/index.php" />
	<input type="submit" name="submit" value="Login" />
</form>
<?php
	}
?>


</body>
</html>
It's pretty a much a simple cut and paste, the only thing you need to do is change your web server's rootpath (if you don't know what it is you can find it in your admin panel -> Tools and Maintenance -> View PHP Info -> find "DOCUMENT_ROOT". Instead you could just have "$_SERVER['DOCUMENT_ROOT']" but I've found that some servers treat this differently as some have a trailing slash and others don't! You can trim the trailing slash though and that add it separately so then it's consistent across all servers.
I don't know where to put this, so hopefully I am right here.

I take a very simple approach to solve this problem.
My Use Case is I have a site with the mybb loginform.
And I have an index.php which redirects everyone to the index.php from the
forum.

With this in mind i take the simple approach and
take the login form, mentioned here.

<?php
  define("IN_MYBB", 1);
  // if you want to redirect
  if ( $_COOKIE['mybbuser']) {
     header('Location: index.php')
 }
 ?>
<!--- ^ this part goes before everything else -->

<!--- your website markup .... --->

<!--- the login form, ignore the divs that's just style  --->
 <form action="member.php" method="POST" id="formular" >
        <input type="hidden" id="action" name="action" value="do_login" />
        <div id="login_form" class="login_form">
            <span class="form">Login</span>
            <div id="block-username" class="">
                <input type="text" id="username" tabindex="1" name="username" placeholder="Username" />
             </div>
             <div id="block-password" class="">
                <input type="password" id="password" tabindex="2" name="password"placeholder="Password" />
           </div>
        </div>
    </form>

Ok, now the really simple thing.
In our index.php we add 4 lines of code
// put this right after the copyright
// true if the user has a cookie else load personal login page
if ( $_COOKIE['mybbuser']) {

// tons of mybb code

// put this at the very end
} else {
  // my custom site is called login.php
  require("login.php");
}

It doesn't provide redirection from your custom site if the user is logged in, but see above
why i don't care.

I hope this helps someone.
I reviewed some mybb code to get this and it's nothing personal,
but the code is very ugly from time to time. Many hardcoded things, less documentation and so on.
I hope the developer will fix this. Wink

Sincerely,
Dr. Ratzeputz

Edit: If forgot to mention, adjust the links to your needs.
Alright, so it seems this thread is rather outdated. Has anything changed since then that I need to know about? I've been having trouble implementing it in 1.8. Follow my progress in this thread: http://community.mybb.com/thread-166685.html
IMO this thread is basically to teach you how to create your pages using MyBB as a core. You could as well use something like Page Manager or OUGC Pages to manages your pages from MyBB.
Here is mine, i had added redirect to current page after login. I'm not php guru, but it's work (for me) and may help someone:

<?php
define("IN_MYBB", 1);
chdir("forum"); // path to MyBB
require "global.php";
?>


<?php

$referer= $_SESSION['current_page'] = $_SERVER['REQUEST_URI'];

if($mybb->user['uid'])
{
// The user is logged in, say Hi
$user = $mybb->user['username'];
echo "Hey, $user.<br>
<a href=\"forum/\">Go to forum</a>";
}
else
{
// The user is not logged in, Display the form
echo "<form action='forum/member.php' method='post'>
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='$referer' />
<input type='submit' class='submit' name='submit' value='Login' /></form><br>";
}
?>
--EDIT - Made a silly mistake, however there's another problem. --

The login works as usual, and everything seems fine. Except for one thing, there is no logout when you're logged in. Just another repeated login form... So I basically never get to display 'thanks for logging in'

And this is my code inside index.html (The main page where I am inserting this)
At the very top, before anything:

<?php
chdir('forum'); // path to MyBB
define("IN_MYBB", 1);
require './global.php';
?>


And then where I want to insert the form:
				<?php

if($mybb->user['uid'])
{
// The user is logged in, say Hi
echo "Hey, $mybbuser[username].<br>
Thanks for logging in.";
}
else
{
// The user is not logged in, Display the form
echo "<form action='forum/member.php' method='post'>
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='#' />
<input type='submit' class='submit' name='submit' value='Login' /></form><br>";
}
?>

Any help would be appreciated.
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