I've noticed the other thread regarding this topic has become out-dated (no longer works) and cluttered with information not relevant to the tutorial. So I've decided to re-create it for the users of this community.
Using a Top Level Domain
Let us assume that your domain name is www.mydomain.com and that your website structure looks like this:
The first thing you want to do is login to the Administration Control Panel of your forums. Navigate to Configuration -> Settings -> General Configuration and scroll down. Look for the cookies section and enter:
Open up your websites index.php file and before any code (literally the very first line), that includes any php or your doctype, place this code:
Now choose the location where you want your login form to appear. Copy and paste this code:
Please take note of the following line. Editing it's value will redirect your users where you want them to be taken after they login.
Redirect you back to your websites index page:
Redirect you to your forum:
Which will produce (in this case my username is eRott obviously):
It is important that you update the following lines to reflect the appropriate installation directory (where you installed your forums) if it is different then the example location. Remember, ../ will always take you back one level or 'group' of folders. The idea is to change the working directory to that of the forums, include the global.php file as well as define the named constant then change back to the directory your website is in.
Using a Sub Level Domain
If you are using a subdomain, then you will need to edit your cookie settings as they are different from above. Let us assume that your domain name is subdomain.somehost.com and your website structure looks like this:
Your cookie settings should then look something like:
I am not entirely sure if those are the correct cookie settings for sub-domains as I do not use a sub-domain and therefore cannot test it out. If someone would like to try it out and let me know, that would be great.
Keywords (help future users find this thread easier): tutorial, mybb, login, system, integrate, website, form
Take care.
Using a Top Level Domain
Let us assume that your domain name is www.mydomain.com and that your website structure looks like this:
Quote:public_html/index.php
public_html/forums/global.php
The first thing you want to do is login to the Administration Control Panel of your forums. Navigate to Configuration -> Settings -> General Configuration and scroll down. Look for the cookies section and enter:
Quote:Cooke Domain: .mydomain.com
Cookie Path: /
Cookie Prefix: (leave blank)
Open up your websites index.php file and before any code (literally the very first line), that includes any php or your doctype, place this code:
<?php
chdir("forums/"); // path to MyBB
define("IN_MYBB", 1);
require("./global.php");
chdir("../");
?>
Now choose the location where you want your login form to appear. Copy and paste this code:
<?php
if($mybb->user['uid'])
{
// If the user if logged in, display a welcoming message.
echo "Welcome back ".$mybb->user['username']."!<br />";
echo "Thanks for logging in.";
}
else
{
// If the user is not logged in, display the login form.
echo "<form action='forums/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>";
}
?>
Please take note of the following line. Editing it's value will redirect your users where you want them to be taken after they login.
Redirect you back to your websites index page:
echo "<input type='hidden' name='url' value='../index.php' />";
Redirect you to your forum:
echo "<input type='hidden' name='url' value='index.php' />";
Which will produce (in this case my username is eRott obviously):
Quote:Welcome back eRott!
Thanks for logging in.
It is important that you update the following lines to reflect the appropriate installation directory (where you installed your forums) if it is different then the example location. Remember, ../ will always take you back one level or 'group' of folders. The idea is to change the working directory to that of the forums, include the global.php file as well as define the named constant then change back to the directory your website is in.
chdir('forums/');
chdir('../');
echo "<form action='forums/member.php' method='post'>";
Using a Sub Level Domain
If you are using a subdomain, then you will need to edit your cookie settings as they are different from above. Let us assume that your domain name is subdomain.somehost.com and your website structure looks like this:
Quote:public_html/index.php
public_html/forums/global.php
Your cookie settings should then look something like:
Quote:Cooke Domain: .subdomain.somehost.com
Cookie Path: /forums/
Cookie Prefix: (leave blank)
I am not entirely sure if those are the correct cookie settings for sub-domains as I do not use a sub-domain and therefore cannot test it out. If someone would like to try it out and let me know, that would be great.
Keywords (help future users find this thread easier): tutorial, mybb, login, system, integrate, website, form
Take care.