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
M@ster Wrote:Am I doing something wrong? Cause its not working for me... Here's what I'm using.

Quote:<?php
chdir('/home/www/poketech.freehostia.com/forum'); // path to MyBB
require './global.php';
?>

and thats at the top of my html page code (stuff) then later on in the page I added this:

Quote:<?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='forums/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='index.php' />
<input type='submit' class='submit' name='submit' value='Login' /></form><br>";
}
?>

But it keeps giving me this error:

Quote:Parse error: parse error, unexpected '&' in /home/www/poketech.freehostia.com/test.php on line 221

What am I doing wrong?

The only thing i can see there is the two little squares in the line shown below if this is line 221 in your test.php file then this may be your problem?

��// The user is not logged in, Display the form

FnT...
Yea I found that out and some other stuff to, but its fixed thanks!
By the way, anyone knows the 'Log out' code for 1.2.10 ???
mmm... nope =[
who has this inbeded into there website?
I've read all the pages here and it appears that the techniques here no longer work for MyBB. I've been doing some digging and analysing the MyBB form / code structure. Turns out there is a hidden field that has been added to MyBB's login form, probably added in 1.2.8 or higher. Anyway this field has allowed me to integrate my website and forum. Without further a do I will post my solution!

Checklist
If your website is located at mydomain.com and your forum at mydomain.com/forum then ensure that under your forums board settings (General Configuration) you set the following:

Cookie Domain = .mydomain.com (yes a leading dot!)
Cookie Path = /

The Code
Ensure the following code is put before EVERYTHING on your php webpage. Before <html> and before <head> etc.
<?php
	define("IN_MYBB",1);
	chdir('forum'); // path to MyBB
	require './global.php';
?>

Now the next bit of code will display one thing if logged in, if not it will display a login box.
<?php

if($mybb->user['uid'] > 0) { // The user is logged in, say Hi
	echo "Hey, ". $mybb->user['username'] .".<br>Thanks for logging in.<br><br>";

} else {

 	// The user is not logged in, Display the form
	echo "<form action='/forum/member.php' method='post'>
	<input type=\"hidden\" name=\"my_post_key\" value=\"$mybb->post_code\" />
	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='mypage.php' />
	<input type='submit' class='submit' name='submit' value='Login' /></form><br>";
}

?>
Note: Replace mypage.php with the page you wish to go to after the log in

You'll notice the difference in this code compared to other's is the line in the form:
<input type=\"hidden\" name=\"my_post_key\" value=\"$mybb->post_code\" />
Without this logging in does not work.
Hope this helps. I'll try to help with any questions if anyone has any.

Regards,
Black Ice
Black_Ice Wrote:I've read all the pages here and it appears that the techniques here no longer work for MyBB. I've been doing some digging and analysing the MyBB form / code structure. Turns out there is a hidden field that has been added to MyBB's login form, probably added in 1.2.8 or higher. Anyway this field has allowed me to integrate my website and forum. Without further a do I will post my solution!

Checklist
If your website is located at mydomain.com and your forum at mydomain.com/forum then ensure that under your forums board settings (General Configuration) you set the following:

Cookie Domain = .mydomain.com (yes a leading dot!)
Cookie Path = /

The Code
Ensure the following code is put before EVERYTHING on your php webpage. Before <html> and before <head> etc.
<?php
	define("IN_MYBB",1);
	chdir('forum'); // path to MyBB
	require './global.php';
?>

Now the next bit of code will display one thing if logged in, if not it will display a login box.
<?php

if($mybb->user['uid'] > 0) { // The user is logged in, say Hi
	echo "Hey, ". $mybb->user['username'] .".<br>Thanks for logging in.<br><br>";

} else {

 	// The user is not logged in, Display the form
	echo "<form action='/forum/member.php' method='post'>
	<input type=\"hidden\" name=\"my_post_key\" value=\"$mybb->post_code\" />
	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='mypage.php' />
	<input type='submit' class='submit' name='submit' value='Login' /></form><br>";
}

?>
Note: Replace mypage.php with the page you wish to go to after the log in

You'll notice the difference in this code compared to other's is the line in the form:
<input type=\"hidden\" name=\"my_post_key\" value=\"$mybb->post_code\" />
Without this logging in does not work.
Hope this helps. I'll try to help with any questions if anyone has any.

Regards,
Black Ice

Question [1]
I did notice that hidden field which I found odd. Can any dev or mod explain to me the purpose of this "post key"?

Question [2]
Secondly, after I login, the form still appears. I believe they problem lies with my cookie settings. So basically, this site I am working on is temporaraily under a folder in my own domain. Could someone please tell me the paths I should be using for this script, and what my forum cookie settings and whatnot should be when:

Install path: www.mydomain.com/subfolder/forums/index.php
Page with the script: www.mydomain.com/subfolder/index.php

Thanks.
Hi eRott,
Under your Admin CP go to Board Settings -> General Configuration. Set the following:

Cookie Domain = .mydomain.com
Cookie Path = /subfolder/

Note: This will allow the cookie to work for anything in the subfolder and below. As long as your log in script is in this folder or under, it should work.
Alright, this code works and I am able to login successfully, the problem is above the login box it says the following
user['uid']) { ��// The user is logged in, say Hi echo "Hey, $mybbuser[username].
Thanks for logging in."; } else { ��// The user is not logged in, Display the form echo "

Then it says

Quote:Username:
password:
Login

And if you put your username correctly with your password it will log you in, but I do not want that stuff to show up above it, any help?
Sorry I'm not quite following. What stuff don't you want to show up above it?
If you mean the line "Hey, [username]. Thanks for logging in." Then just delete that line...though I don't think that's what you mean.
Could you maybe post a screenshot of what you mean?
Okay heres a screen of what Im getting
If you look onto the right hand side you'll see the login box.
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