MyBB Community Forums

Full Version: Integration with website
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone !
I have problems with integration my website with forum.

Link to website:
theroyalfive.com

Link to forum:
theroyalfive.com/forum

In ACP cookie source:
/forum/

...
Functions from integration class doesn't work.

I try this:
define('IN_MYBB', NULL);
require("forum/global.php");
require_once 'classes/MyBBIntegrator.php';
require_once MYBB_ROOT.'inc/class_parser.php';
$MyBBI = new MyBBIntegrator($mybb, $db, $cache, $plugins, $lang, $config);

And this:
$forumpath = './forum/';

chdir($forumpath);
define("IN_MYBB", 1);
require('../forum/global.php');

require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;
chdir('../');

include ("classes/MyBBIntegrator.php");
$MyBBI = new MyBBIntegrator($mybb, $db, $cache, $plugins, $lang, $config);

I use this code in header to login and it is work.
<?php

if($mybb->user['uid'])
{
// The user is logged in, Display Welcome Message
echo "Welcome, <a href='#'>".$mybb->user['username']."</a>.<br>
<a href='/forum/member.php?action=logout&amp;logoutkey={$mybb->user['logoutkey']}'>
Logout</a>

<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='15' maxlength='30' /><br />
    Password: <input type='password' name='password' size='15' />
    <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' /><br /><br />
    </br></form><br>";
}

?>

But function login from class integration doesn't work.

I wanna check logstatus with function isLoggedIn(). But it always return false.

I have one solution for this. Change cookies source in ACP to " ". The function isLoggedIn is work! But logout in my forum was stop work.

I dont know what i must do =/ I spend a lot time on this and cant find solution. Please help!
You need to edit your cookie path. Put / for your cookie path this way the cookies will be accessible outside of the forum directory. After doing this, you may need to clear your cookies. You can use this for a function:
function isLoggedIn()
{
global $mybb;
if($mybb->user['uid'])
{
return true;
}
else
{
return false;
}
}
Thank you a lot ! ! !
Well that there are people like You Big Grin
.....
But i have one problem yet.

I check this function from Integration class and it is working:
echo ($MyBBI->isLoggedIn()) ? 'You are logged in' : 'You are not logged in'; 

But this function is not:
$MyBBI->logout();

Already i use:
<a style='font-weight: bold; font-size: 12px;' href='/forum/member.php?action=logout&amp;logoutkey={$mybb->user['logoutkey']}'>
				Logout</a>

But this is a link and sends me to the forum and there Logs out.

Sorry Man but maybe you have any solution for this one?
Try this:

function logout()
{
global $mybb, $db;
setcookie($mybb->settings['cookieprefix'] . "mybbuser", "", time()-31536000, "/", $mybb->settings['cookiedomain']);
setcookie($mybb->settings['cookieprefix'] . "sid", "", time()-31536000, "/", $mybb->settings['cookiedomain']);
if($mybb->user['uid'])
	{
		$time = TIME_NOW;
		// Run this after the shutdown query from session system
		$db->shutdown_query("UPDATE ".TABLE_PREFIX."users SET lastvisit='{$time}', lastactive='{$time}' WHERE uid='{$mybb->user['uid']}'");
		$db->delete_query("sessions", "sid='".$session->sid."'");
	}
/* Optionally use the header function using Location as the header type and your desired url.  * Make sure to exit the current script after doing so.
* Example:
* header("Location: index.php");
* exit;
*/
}
It's hard to tell but it doesn't work =/
Did it give any kind of error message?
echo "xxx";
    global $mybb, $db;
	setcookie($mybb->settings['cookieprefix'] . "mybbuser", "", time()-31536000, "/", $mybb->settings['cookiedomain']);
	setcookie($mybb->settings['cookieprefix'] . "sid", "", time()-31536000, "/", $mybb->settings['cookiedomain']);
	if($mybb->user['uid'])
    {
    	echo "xxx2";
        $time = TIME_NOW;
        // Run this after the shutdown query from session system
        $db->shutdown_query("UPDATE ".TABLE_PREFIX."users SET lastvisit='{$time}', lastactive='{$time}' WHERE uid='{$mybb->user['uid']}'");
        $db->delete_query("sessions", "sid='".$session->sid."'");
    }

Body shows echo and echo in if. How I can check errors? Because i dont see anything. Function is working but it is not logout.