Page 1 of 1

Accessing phpBB3 variables outside phpBB3

Posted: Tue Jul 01, 2008 1:58 pm
by TinaMay
I am trying to verify whether or not someone is logged into the forum from outside the forum. I found the following article for phpBB2 - however it doesn't seem to work for phpBB3. Any thoughts on what to do to get it to work in phpBB3? Thanks.


http://www.phpbb.com/community/viewtopi ... 5&t=576024

Re: Accessing phpBB3 variables outside phpBB3

Posted: Tue Jul 01, 2008 2:09 pm
by TinaMay
More specifically does phpBB3 have a session_pagestart () function b/c this is the error I get when I run the code listed below. THANKS!!!!!!


ERROR:
Fatal error: Call to undefined function: session_pagestart() in /homepages/29/d244682546/htdocs/ExDelicti/MemberPHP.php on line 11


CODE:

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './phpBB3/';

include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//

if($userdata['session_logged_in'])
{
echo('Hi ' . $userdata['username'] . '!');
}
else
{
echo('You are a guest');
}

?>

Re: Accessing phpBB3 variables outside phpBB3

Posted: Tue Jul 01, 2008 2:10 pm
by Brf

Re: Accessing phpBB3 variables outside phpBB3

Posted: Tue Jul 01, 2008 2:23 pm
by TinaMay
Thanks for the article. I don't quite think it solves my dilemna though. I need to access the variables outside the phpBB instance. The article seems to explain how to access them from within the instance. Am I missing something???


Thanks again!

Re: Accessing phpBB3 variables outside phpBB3

Posted: Tue Jul 01, 2008 2:27 pm
by Brf
It shows you what code to use to replace what you have above.

Re: Accessing phpBB3 variables outside phpBB3

Posted: Tue Jul 01, 2008 2:54 pm
by TinaMay
Thanks -- I think it's getting there. So, I used the "if ($user->data['user_id'] == ANONYMOUS)" code from the article - but it's still not working. Do I need to call an additional function? The totality ofthe code is re-produced below. Thanks!


<?php
define('IN_PHPBB', true);
$phpbb_root_path = './phpBB3/';

include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

if ($user->data['user_id'] == ANONYMOUS)
{
echo('NOT LOGGEDIN');
}
else
echo('hI');
?>

Re: Accessing phpBB3 variables outside phpBB3

Posted: Tue Jul 01, 2008 2:57 pm
by Brf
Those includes are for phpbb2.
You will have to use the code from the article I linked to.

Re: Accessing phpBB3 variables outside phpBB3

Posted: Tue Jul 01, 2008 4:58 pm
by TinaMay
Thanks! That did the trick.

Does anyone happen to know how to navigate up the file structure through? I am using "../" and its not working. Is it OK to have the phpBB3 folder be in a completely different folder than the folder that is trying to access the variables?
My code is below:

$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../../../ExDelicti/phpBB3/';

Re: Accessing phpBB3 variables outside phpBB3

Posted: Tue Jul 01, 2008 5:04 pm
by Brf
Yes. Each ../ would go up one folder level.
Whether it works for you or not depends on your host's permissions at that level. If you are trying toi jump to another user or domain, it will probably not work.

Re: Accessing phpBB3 variables outside phpBB3

Posted: Tue Jul 01, 2008 5:10 pm
by TinaMay
Got it. Thanks again for all of your help!

Re: Accessing phpBB3 variables outside phpBB3

Posted: Tue Jul 01, 2008 5:31 pm
by nakendlom
I have a problem which is close to challenge described here. I have to login user on the page which is not within PHPBB and moreover, the user when he clicks on PHPBB link from my page should enter PHPBB and be already logged in. So I found the way to login user on my page, but I didn't manage to start session properly so that when the user leave my page it entered PHPBB already logged in.
Here is my code for logging an user in:
<?php
define('IN_PHPBB', true);
define('PHPBB_DB_NEW_LINK',true);
$phpbb_root_path = PHPBB_ROOT_PATH;
$phpEx = 'php';
include($phpbb_root_path . 'common.' . $phpEx);


$auth->login('username','password');

//after this I can see user data in $user variable - it's ok. But if user goes to some PHPBB page than, it have to login again.
?>

Thank's for any help.