MyBB Community Forums

Full Version: SDK and Login Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
chdir('./forums/');
require('./global.php');

function is_logged_in()
{
global $mybb;
if($mybb->user['uid'])
{
return true;
}
else
{
return false;
}
}

if(is_logged_in())
{
echo 'Hey welcome back!';
}
else
{
echo 'Want to register?';
}

Try using the 'require' for the MyBB global.php
DennisTT Wrote:
chdir('./forums/');
require('./global.php');

function is_logged_in()
{
global $mybb;
if($mybb->user['uid'])
{
return true;
}
else
{
return false;
}
}

if(is_logged_in())
{
echo 'Hey welcome back!';
}
else
{
echo 'Want to register?';
}

Try using the 'require' for the MyBB global.php

that might work for the login, but I won't be able to access the datacache throughout the site that way will I?
Can you show us the code/files that you are using at the minute? I guess you are referring to the cache in the database? Are you constructing it youself or using the mybb files to construct it?

The require global.php will do everything for you. Construct the database, connect to db, and more importantly, give you the mybb class which has the user array/information.
decswxaqz Wrote:Can you show us the code/files that you are using at the minute? I guess you are referring to the cache in the database? Are you constructing it youself or using the mybb files to construct it?

Here's what I have in my common include file used on all pages on my site, including the forum.

require_once "./inc/class_sdk.php";
$mybbSDK = new MyBBSDK;
$mybbSDK->connect();
$stats = $mybbSDK->boardStats();
$newscache = $mybbSDK->getNewsCache();
$authorcache = $mybbSDK->getAuthorCache();
$soundpackcache = $mybbSDK->getSoundPackCache();
$soundstats = $mybbSDK->getSoundStats();
$categorycache = $mybbSDK->getCategoryCache();
$languagecache = $mybbSDK->getLanguageCache();
$latestpostscache = $mybbSDK->getLatestPostsCache();

They are so extra functions I've added to class_datacache.php and class_sdk.php.

Then I check if the user is logged in:
if($_COOKIE['mybbuser'])
					{
                        unset($user);
                        global $userUID;
						$logon = explode("_", $_COOKIE['mybbuser'], 2);
						$userUID = $logon[0];
						//echo "<br><br><b>User:  ".$userUID."<br><br>";
						$user = $mybbSDK->getProfile($userUID);
					}
But this doesn't seem to always work reliably.

If you wanna see anything else, let me know. Cheers for trying to help Big Grin
Send a query to the users table
SELECT loginkey FROM mybb_users WHERE uid=$login[0]
Pseudo-code:
Get the login key from the query
If login key == $login[1], then is valid cookie
else, not a valid cookie
DennisTT Wrote:Send a query to the users table
SELECT loginkey FROM mybb_users WHERE uid=$login[0]
Pseudo-code:
Get the login key from the query
If login key == $login[1], then is valid cookie
else, not a valid cookie
Thanks Smile All seems to be working great now cheers Big Grin
Pages: 1 2