Accessing phpBB3 variables outside phpBB3

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Scam Warning
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
Locked
TinaMay
Registered User
Posts: 11
Joined: Thu Jun 26, 2008 4:14 pm

Accessing phpBB3 variables outside phpBB3

Post 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
TinaMay
Registered User
Posts: 11
Joined: Thu Jun 26, 2008 4:14 pm

Re: Accessing phpBB3 variables outside phpBB3

Post 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');
}

?>
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53379
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Accessing phpBB3 variables outside phpBB3

Post by Brf »

TinaMay
Registered User
Posts: 11
Joined: Thu Jun 26, 2008 4:14 pm

Re: Accessing phpBB3 variables outside phpBB3

Post 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!
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53379
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Accessing phpBB3 variables outside phpBB3

Post by Brf »

It shows you what code to use to replace what you have above.
TinaMay
Registered User
Posts: 11
Joined: Thu Jun 26, 2008 4:14 pm

Re: Accessing phpBB3 variables outside phpBB3

Post 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');
?>
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53379
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Accessing phpBB3 variables outside phpBB3

Post by Brf »

Those includes are for phpbb2.
You will have to use the code from the article I linked to.
TinaMay
Registered User
Posts: 11
Joined: Thu Jun 26, 2008 4:14 pm

Re: Accessing phpBB3 variables outside phpBB3

Post 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/';
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53379
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Accessing phpBB3 variables outside phpBB3

Post 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.
TinaMay
Registered User
Posts: 11
Joined: Thu Jun 26, 2008 4:14 pm

Re: Accessing phpBB3 variables outside phpBB3

Post by TinaMay »

Got it. Thanks again for all of your help!
nakendlom
Registered User
Posts: 2
Joined: Tue Jul 01, 2008 5:22 pm

Re: Accessing phpBB3 variables outside phpBB3

Post 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.
Locked

Return to “[3.0.x] Support Forum”