MyBB Community Forums

Full Version: Quick Login box
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Im trying to make a login box which is on the index page outside the forum root. Using this code from another post:

above any other code:
chdir('forums'); // path to MyBB
define("IN_MYBB", 1);
require './global.php';

login form thing
// The user is logged in, say Hi
echo "Hey, $mybbuser[username].<br />
Thanks for logging in.<br />";
echo "<a href=\"{$mybb->settings['bburl']}/private.php\">{$lang->welcome_pms}</a> {$lang->welcome_pms_usage}";
// 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' style='border-radius:10px;' /><br />
Password: <input type='password' name='password' size='25' style='border-radius:10px;' />
<input type='hidden' name='action' value='do_login'>
<input type='hidden' name='url' value='index.php' />
<input type='submit' class='submit' name='submit' value='Login'/></form><br>";

The problem im having is that for some reason it while im logged in on the forum doesnt show this on the main site. It constantly shows the else loop.
Asking to sign it while the user is already signed in. Any solutions for this problem would be really welcome.
Also i tried it with the normal portal page (pulling it out of the root and have the same issue there) with telling me " hello guest ... loging/register etc. "

Has something to do with the fact that the page doesnt find all of the mybb cookies for some reason.

Jup has to do with the cookies.
My cookie path is /forum/ so apparently that means they are only accessible by that folder (/forum/).
What would happen if i make it / again to make it the cookies set to the root. Would the cookie then still be accessible by Mybb? and accessible through out the whole domain ?

How do i use
To get the cookies needed for the above code?
Still trying to figure this out wondering two things which i think are the only options:


What would happen if i set the cookie path to root while the forum is in /forum/ ?
Would the cookies then still be useable by MyBB or does this break it completely?

I did find the function which sets the cookies in member.php

line 252 down:
$user_info = $userhandler->insert_user();

		if($mybb->settings['regtype'] != "randompass" && !$mybb->cookies['coppauser'])
			// Log them in
			my_setcookie("mybbuser", $user_info['uid']."_".$user_info['loginkey'], null, true);

Could i somehow change that to also set a cookie for the root or is this not possible?