Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading phpBB in Laravel code conflicts

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();.

like image 877
JaChNo Avatar asked Sep 23 '16 23:09

JaChNo


2 Answers

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.

like image 167
Stanimir Stoyanov Avatar answered Nov 10 '22 23:11

Stanimir Stoyanov


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.

like image 2
Alexandre Tranchant Avatar answered Nov 10 '22 22:11

Alexandre Tranchant