Trying to integrate users from my forum (phpBB3) to my website

I’m a new coder here, and this is really beyond my skill set, but I’m trying my best to make this work.

I have a forum I use on my website (phpBB3) which has many members/users registered.

To access some other features of my website, I want to set up a user login. I would like to just have the users login on the website but check their login against the phpBB3 user database.

I have asked for help on the phpBB3 forums, but there really is no support there (and there have been no replies.)

A google search indicates this should be possible and has resulted in the following info link:

On my main directory, I have set up a folder called “login”. I have placed 2 files in it: login-test.php and login-test-index.php

login-test.php

<?php ?>
<form method="post" action="/forum/phpBB3/ucp.php?mode=login">
<label for="username">Username: </label> <input type="text" name="username" id="username" size="40" /><br /><br />
<label for="password">Password: </label><input type="password" name="password" id="password" size="40" /><br /><br />
<label for="autologin">Remember Me?: </label><input type="checkbox" name="autologin" id="autologin" /><br /><br />
<input type="submit" value="Log In" name="login" />
<input type="hidden" name="redirect" value="../../login/login-test-index.php" />
</form>

login-test-index.php

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './forum/';
//$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/phpBB3/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

echo('\user->data[\'user_id\']'.$user->data['user_id'].'<br />');
echo('\user->data[\'username\']'.$user->data['username'].'<br />');

?>

Note: A friend provided the syntax for the echo statements – those are beyond my understanding/comprehension.

When I try using the login-test.php page, it then sends me to my forum’s login page where I received a message saying “The submitted form was invalid. Try submitting again”

When I login from the forum login page that came up, then I do get redirected to login-test-php, however nothing happens as I get a 500 error.

Is the formatting right in those echo statements?

Any help/guidance would be greatly appreciated.

These are also the other reference pages involved:
https://wiki.phpbb.com/User_class
https://wiki.phpbb.com/User.setup

Thank you.

**Edit: I have tried commenting out the echo statements to see if they were causing the “500 error”, but I still get the same error.

The main difference I can see is here. In the first line of your login-test code, you specify an action for this path:

<form method="post" action="/forum/phpBB3/ucp.php?mode=login">

which suggests that your forum root is in /forum/phpBB3/. Yet in the test page, you use

$phpbb_root_path = './forum/';

which is different. In that article, the two folders are the same. So you could try adding phpBB3/ on the end of that second line.

I think the complex bit is the quote-escaping (putting a \ before a single quote is necessary if you enclose the full string with single quotes, so PHP knows the difference between a quotation mark inside the string, and the closing one), and if you changed those two lines to

var_dump($user->data['user_id']);
... and so on...

it would have the same effect of showing the variable name and its contents.

Thanks droopsnoot. I tried fixing that, but it seems like nothing is happening now at the session stage. I put in some testing code. Once it gets to the “$user->session_begin();” line, then nothing after it runs/outputs.

Any idea why this would be the case?

echo 'testing 1/';

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/phpBB3/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

echo "testing 2/";

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

echo 'testing 3';

Are phpBB and phpBB3 the same code base? That article you linked to is from 2012 and based on phpBB.

But it does say:

Not without knowing what those functions do, sorry. Which one does it fail on? That is, can you narrow it down further with echo statements between each one?

I still won’t know, but someone else might.

1 Like

It stops working as soon as it gets to here:
$auth->acl($user->data);

I think I have better luck looking at areas of code. eg.It may be a problem the $auth / $user object on that line. It may be a problem with the $user object the line before. (theoretically the cause of an error could be any previous line but in my experience it’s usually nearby)

// Start session management
$user->session_begin();
$auth->acl($user->data); 

I don’t know what session_begin() entails, but the name suggests it involves SESSION which might be “already sent” erroring.