MyBB Community Forums

Full Version: Login Box on Main Website
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How would one go about making a log-in box for MyBB on the main website?

I have tried copying all the code from the index page and finally got it to the point that it would create the user name and password boxes when you click 'log in' but it doesn't actually work. It just directs to an error 404 page, and going back and refreshing the first page, it is not being saved and asks you to log in again.

I'd like to have a small log in box to MyBB that appears on every page of my website and then users can click 'log in' and enter their information and it will log them in, and if I could just get this to work, I'm sure I'd be able to get it to do what I ultimately want, use MyBB permissions to make certain pages hidden from people, let them make comments, etc.

Any ideas how I could go about this? (Feel free to move this thread, as I'm not sure this is the correct place for it..) Toungue

P.S. MyBB 1.4 ROCKS guys!! Great job! Smile
One pointer that may or may not help that I have just discovered thanks to another member is that when you click on that login button it causes a post action (as you would expect) to a file called member.php This was pointed out to me in another thread (thanks pepotiger Smile ) and led me to discover a solution for my site. I will explain it here in case it helps at all.

So for example, if your forum is installed in www.mydomain/forum but then you build a page outside of the forum folder which contains all the code e.g. www.mydomain/anotherpage/index.php, when you click on the login button in the quick login, it expects to find the following page in the following path www.mydomain/anotherpage/member.php This would then process the login and return you back to where you were. Because you don't have that file in that folder, you get the 404 error and, because it could not process the code held in the member.php file, when you refresh you will not be logged in.

You could therefore place a copy of the member.php file in each folder where you have a web page outside the forum root folder, but that would be a pain, and my understanding is that it would not be that straightfoward as it could then cause a chain of events where it expects other pages from within the forum folder too once it has loaded the member.php file in.

The more logical answer would be to alter the command attached to the quick login button itself so that regardless of whether you are logging in from a page held within your forum directory, or a page created outside your forum directory, it will always know to load in the member.php file that resides in the root of your forum directory.

The command that controls the posting action for the quick login file is located in the jscripts folder and the file you are looking for is the general.js file.

About half way down the page (line 377 approx) is the code that controls the quick login. One line says:

form.setAttribute("action", "member.php");

Change this to say:

form.setAttribute("action", "http://www.yourdomain/yourforumrootfoldername/member.php");

From now on, regardless of where you log in it will always look for the member.php file there. Obviously if you ever change the location of your forum folder you will need to update this as well for the login to work. You may also find you need to clear your browser cache after changing the code to see it take effect.

If all that seems too much, there is another quick solution, which is to make the quick login link act more like it did in version 1.2 i.e you click on login and it directs you to another page to log in and then returns you back to where you were. This works for pages outside the forum folder (well, did for me anyway). To do this, open up your admin control panel, go to templates, find the header template section, open up the template file named header_welcomeblock_guest find the line of code that says:

<a href="{$mybb->settings['bburl']}/member.php?action=login" onclick="MyBB.quickLogin(); return false;">

and change it to:

<a href="{$mybb->settings['bburl']}/member.php?action=login" onclick="">

Now instead of the link working like a quick login, it will direct you to a more traditional log in page.

Hope that helps.
MyBB's files were designed to be used by MyBB, not anywhere else unless otherwise specified
Umm, the easiest is to change the action="member.php" into action="http://site.com/forums-directory/member.php" and there you go.