Loading phpBB in Laravel code conflicts
Asked Answered
F

4

8

I am trying to access some of the functions within phpBB from my Laravel application, this is for actions such as adding a user when a registration happens on my main site and autologins.

PhpBB is installed under /public/forums and I have updated .htaccess to allow it. I am able to access and use it just fine.

I have a helper that was originally constructed for codeigniter but should translate in to the laravel world. I am loading it as a helper by putting it under app, loading it using

use App\Helpers\phpBBHelper;

and I access the functions as such

   $ph = new phpBBHelper();
   $ph->addPhpbb3User('dave','password','[email protected]');

At the top of my helper I have this constructor

public function __construct() {

    // Set the variables scope
    global $phpbb_root_path, $phpEx, $cache, $user, $db, $config, $template, $table_prefix;

    define('IN_PHPBB', TRUE);
    define('FORUM_ROOT_PATH', 'forum/');

    $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : FORUM_ROOT_PATH;
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    // Include needed files
    include($phpbb_root_path . 'common.' . $phpEx);

    // Initialize phpBB user session
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();

    // Save user data into $_user variable
    $this->_user = $user;   
}

When i execute the code I get a server 500 error

PHP Fatal error:  Call to a member function getScriptName() on null in
/home/ubuntu/workspace/public/forum/phpbb/session.php on line 50

which is this line

$script_name = $request->escape($symfony_request->getScriptName(), true);

I have found a post on stack overflow that exactly refers to my issue but the resolution of that issue was never posted

Laravel conflicting

In that thread it was suggested that because both phpBB and Laravel both use composer it was causing a conflict when loading the classes. I am not sure if that is true.

But Laravel is certainly affecting phpBB when I call the $user->session_begin();.

Fricke answered 23/9, 2016 at 23:6 Comment(1)
for session conflict in laravel try SESSION_DRIVER with cookie or memcached in .envHoopes
C
5

I would suggest to not reinvent the wheel and use already coded extension like lara-auth-bridge. The registration is simply inserting the right rows in the right tables, not familiar with phpBB3 in particular, but you could see the changes in the database after a new account is created.

Edit: You can surround the problematic code in try {} catch {} block in case that the error is not fatal for the registration itself so the server will not end up with 500.

Candiscandle answered 26/9, 2016 at 7:58 Comment(3)
I have looked at the lara auth bridge and whilst it does take care of the adding user. The library I am attempting to use has a great deal more functionality in it. whilst your has propsed a work around it does not answer my original question.Fricke
Well, you didn't mention what library you're trying to use in the question. Could you try to wrap the crashing code in try {} catch {} block then? From the code you supplied we can only assume that for some reason $symfony_request is null, so you should check out why that variable is not initialized.Candiscandle
I did mention there was a helpers library I should have made it clearer that the add user function was not the only function I wanted. Apologies. but the problem. as for the symfony_request not being initialized that really is the root of the issue. If I knew why that was not being initialized I would imaging the rest of the solution would workFricke
U
2

When two applications had to communicates, I updated the twice. PhpBB is written to be upgradable with extension. You can develop a phpBB extension which is an API to create a new user.

Your new extension uses XML-RPC over HTTP for all communications between your laravel app and the forum system. You define a route which receives informations about the new users and then you analyse the creation process in phpbb. This way is easier because you're inside the phpBB/symfony Framework.

In your laravel application, you have to call the API to start communications.

Ultramicroscopic answered 26/9, 2016 at 11:19 Comment(1)
HI,I guess this is an alternative but this does not answer my original question. ThanksFricke
A
2

The error clearly indicates that the symfony_request object is null. By browsing the source code a bit, I found that that variable (and many others) are expected to exist globally.

It seems like you have to include the phpBB/app.php file. It creates most of the objects needed.

update:

Actually, you are including the common file which does most of the initial setup. Maybe just making a global

$symfony_request = $phpbb_container->get('symfony_request');

will work. (I can't test it myself now, just throwing ideas)


(If possible, though, I'd try another library. I don't like those globals. Nobody does. It makes tracing stuff and debugging harder, as this question shows)

Albania answered 26/9, 2016 at 14:40 Comment(0)
P
2

To be able to get the session request, you have to be sure both the PhpBB forum and your Laravel application use the same kind of cookie :

  • Same domain
  • Same path
  • Same secure flag

Are these settings ok?

Practical answered 30/9, 2016 at 8:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.