Solved: 11 Years, 7 Months, 4 Weeks ago Integrating MyBB login into website. (Problem)
#1
Solved: 11 Years, 7 Months, 4 Weeks ago
Hi. My website is http://kh13.com/ and my forum is http://kh13.com/mybb/.

On the index page, I have placed the following code before any HTML.
<?php
chdir('mybb'); // path to MyBB
define("IN_MYBB", 1);
require './global.php';
?>

Then, where I want the login forum to appear, I have placed this:
<?php echo "$welcomeblock"; ?>

I included all relevant CSS and put the following in the <head> tag:
<script type="text/javascript" src="http://kh13.com/mybb/jscripts/prototype.js?ver=1400"></script> 
<script type="text/javascript" src="http://kh13.com/mybb/jscripts/general.js?ver=1400"></script> 
<script type="text/javascript" src="http://kh13.com/mybb/jscripts/popup_menu.js?ver=1400"></script> 
<script type="text/javascript"><!--
var cookieDomain = ".kh13.com";
var cookiePath = "/mybb/";
var cookiePrefix = "";
var deleteevent_confirm = "Are you sure you want to delete this event?";
var removeattach_confirm = "Are you sure you want to remove the selected attachment from this post?";
var loading_text = 'Loading. <br />Please Wait..';
var saving_changes = 'Saving changes..';
var use_xmlhttprequest = "1";
var my_post_key = "<?php echo "$mybb->post_code"; ?>";
var imagepath = "images/midnight";
// --></script>

This creates a welcome block identical to the one that is included in my forum. However, when I login at http://kh13.com/ and submit, it redirects me to http://kh13.com/member.php (instead of reloading the current page) and the welcome block shows no signs that I have logged in (it still shows the guest message).

What am I missing? What do I need to do to get the login form to work on non-MyBB parts of the site? Thanks.

You can login using the following details to test it:
Username: Test
Password: password
#2
Solved: 11 Years, 7 Months, 4 Weeks ago
You need to set it so that where the login form is, it sets it to http://kh13.com/mybb/member.php?action=login (I think), and it should work..
#3
Solved: 11 Years, 7 Months, 4 Weeks ago
(2009-01-18, 03:17 AM)TomL Wrote: You need to set it so that where the login form is, it sets it to http://kh13.com/mybb/member.php?action=login (I think), and it should work..

As far as I can see, it does link to that location... if I look at the source of the page (after the PHP has loaded that template), then the code shows this:
<span id="quick_login">Hello There, Guest! <a href="http://kh13.com/mybb/member.php?action=login" onclick="MyBB.quickLogin(); return false;" class="login">Login</a><a href="http://kh13.com/mybb/member.php?action=register" class="register">Register</a></span>

So, any idea what I need to change? Thanks for the reply.

I couldn't find the CSS for #quick_login anywhere. In which file is that located?
#4
Solved: 11 Years, 7 Months, 4 Weeks ago
(2009-01-18, 03:20 AM)DChiuch Wrote:
(2009-01-18, 03:17 AM)TomL Wrote: You need to set it so that where the login form is, it sets it to http://kh13.com/mybb/member.php?action=login (I think), and it should work..

As far as I can see, it does link to that location... if I look at the source of the page (after the PHP has loaded that template), then the code shows this:
<span id="quick_login">Hello There, Guest! <a href="http://kh13.com/mybb/member.php?action=login" onclick="MyBB.quickLogin(); return false;" class="login">Login</a><a href="http://kh13.com/mybb/member.php?action=register" class="register">Register</a></span>

So, any idea what I need to change? Thanks for the reply.

I couldn't find the CSS for #quick_login anywhere. In which file is that located?
Yes. But that's generated by what you set your forum's directory to(when you installed it). I don't see any way to get it to work without the action="" of the login form being set automatically..
#5
Solved: 11 Years, 7 Months, 4 Weeks ago
Oh, I think the member.php problem lies in one of the Javascript files. The code in general.js used to say "form.setAttribute("action", "member.php");", and I have changed it to "form.setAttribute("action", "http://kh13.com/mybb/member.php");". When I login now, it reloads the current page. However, it still shows the guest message.
#6
Solved: 11 Years, 7 Months, 4 Weeks ago
(2009-01-18, 03:33 AM)DChiuch Wrote: Oh, I think the member.php problem lies in one of the Javascript files. The code in general.js used to say "form.setAttribute("action", "member.php");", and I have changed it to "form.setAttribute("action", "http://kh13.com/mybb/member.php");". When I login now, it reloads the current page. However, it still shows the guest message.
I think it's because it sets the cookie for http://kh13.com/mybb/, not http://kh13.com..I could be wrong though:p I'm pretty sure that's why..
#7
Solved: 11 Years, 7 Months, 4 Weeks ago
(2009-01-18, 03:35 AM)TomL Wrote:
(2009-01-18, 03:33 AM)DChiuch Wrote: Oh, I think the member.php problem lies in one of the Javascript files. The code in general.js used to say "form.setAttribute("action", "member.php");", and I have changed it to "form.setAttribute("action", "http://kh13.com/mybb/member.php");". When I login now, it reloads the current page. However, it still shows the guest message.
I think it's because it sets the cookie for http://kh13.com/mybb/, not http://kh13.com..I could be wrong though:p I'm pretty sure that's why..

Oh, thanks a lot. I changed the cookie path and now everything seems to be working.

I have one more question though... at the start of the page, I used the following code:
<?php
chdir('mybb');
define("IN_MYBB", 1);
require './global.php'; ?>

However, on other sections of my site (such as kh13.com/something/), the chdir location would have to be "../mybb", for example. Because the <head> tags are generated by an include file, how can the chdir code always link to kh13.com/mybb? I have tried chdir('http://kh13.com/mybb'), however this did not work. Is it possible?
#8
Solved: 11 Years, 7 Months, 4 Weeks ago
(2009-01-18, 03:42 AM)DChiuch Wrote:
(2009-01-18, 03:35 AM)TomL Wrote:
(2009-01-18, 03:33 AM)DChiuch Wrote: Oh, I think the member.php problem lies in one of the Javascript files. The code in general.js used to say "form.setAttribute("action", "member.php");", and I have changed it to "form.setAttribute("action", "http://kh13.com/mybb/member.php");". When I login now, it reloads the current page. However, it still shows the guest message.
I think it's because it sets the cookie for http://kh13.com/mybb/, not http://kh13.com..I could be wrong though:p I'm pretty sure that's why..

Oh, thanks a lot. I changed the cookie path and now everything seems to be working.

I have one more question though... at the start of the page, I used the following code:
<?php
chdir('mybb');
define("IN_MYBB", 1);
require './global.php'; ?>

However, on other sections of my site (such as kh13.com/something/), the chdir location would have to be "../mybb", for example. Because the <head> tags are generated by an include file, how can the chdir code always link to kh13.com/mybb? I have tried chdir('http://kh13.com/mybb'), however this did not work. Is it possible?
Neither of those work? I think you can't use ../ in the chdir() function..
#9
Solved: 11 Years, 7 Months, 4 Weeks ago
Quote:Neither of those work? I think you can't use ../ in the chdir() function..

Well I haven't tried using "../" yet, I've only put the PHP code on the index page.

Instead of adding the PHP code to every page, I was just going to put it into a file which every page includes. However, if I simply use chdir(mybb), then pages in other directories will not link to the correct location. I tried to fix this by using chdir(http://kh13.com/mybb), however that did not work.
#10
Solved: 11 Years, 7 Months, 4 Weeks ago
You can try doing, and replacing PAGE_NAME.PHP with the current page:
$dir = str_replace($_SERVER['PHP_SELF'], "PAGE_NAME.PHP", $_SERVER['PHP_SELF']);
chdir($dir);

Not sure if it'll work, but it's worth a try.:p


Forum Jump:


Users browsing this thread: 1 Guest(s)