MyBB Community Forums

Full Version: Make quicklogin folder independent
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Currently the quick login form is dependent on the location of the page calling it. In fact, it requires that the page calling it is in the forums root folder or the login fails not finding member.php. This does not allow pages outside the forum root folder to fully integrate into the board.

A simple solution is to alter the 'header_welcomeblock_guest' template as follows
onclick="MyBB.quickLogin('{$mybb->settings['bburl']}/')

and then edit the general.js file to include a 'bburl' argument and the single modification to the action attribute

	quickLogin: function(bburl)
	{		
		if($("quick_login"))
		{
			var form = document.createElement("form");
			form.setAttribute("method", "post");
			form.setAttribute("action", bburl + "member.php");

These simple changes allow any page outside the forum root folder to fully integrate with the forum. It will even maintain the referrer URL and return the user back to the page logged in from.
Why are you using MyBB's quick login form outside of MyBB?
I am building pages that integrate with MyBB but the way I have my site invisioned, I do not want all the non-core MyBB pages inside the forums folder.

For instance, I am about done with with a customizable 'garage' plug-in that is in my site's root, but that is one level up from the forum folder. I like the integration of MyBB and the user tracking, data handling, etc, so I am building this plug-in (and the rest of my site using plug-ins) around it.

MyBB is at www.mydomain.tld/board but the garage is at www.mydomain.tld/garage.php
one thing to add, is that so far, nearly all other code I am reusing/interacting with allows for it's use outside the folder MyBB is installed in as the $mybb->settings['bburl'] is used in most URLs.

Quick login was the only thing that needed modification to be fully functional
Essentially the quick login is useless on non-forum-root pages with the default MyBB cookie configuration, though. It would have to redirect the users to the main forums. Else, they'd be logged out in the custom pages.

I just thought I'd point that out, not that there isn't any workarounds, though.
Sorry, but you are wrong. I have it enabled on my forum already and it is working. I've made the change above and the quick login works fine on both inside and outside the forum root (subdomains may be another issue). It works in FF2, FF3, Chrome, and IE7 and 8. My cookie config is simply '.mydomain.tld'

I only ask for this to be put into the core code is to avoid loss of functionality when I do upgrades.
Hmm, you stay logged in on non-forum pages? I could never get that to work properly.
You need to modify a bit of the code in the outside of forum root pages, here is an example

// set the path to your forums directory here (without trailing slash)
$forumdir = "./board";
// end editing

//change working directory to allow board includes to work
$forumdirslash = $forumdir."/";
$change_dir = "./";

if(!@chdir($forumdir) && !empty($forumdir))
{
	if(@is_dir($forumdir))
	{
		$change_dir = $forumdir;
	}
	else
	{
		die("\$forumdir is invalid!");
	}
}

//include board files
require_once $change_dir."/global.php";
require_once MYBB_ROOT."inc/functions.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_user.php";
require_once MYBB_ROOT."inc/class_parser.php";

//include garage files
require_once MYBB_ROOT."inc/functions_garage.php";

//change directory back to current where script is
@chdir($current_dir);

Doing this includes all the required functionality to use the built-in session/user management. Once MYBB_ROOT has been defined, it makes it easy to use files from MyBB in your own code. No need to recreate/mimic core functions