title: What is "a" correct way to integrate a Zend2 application with PHPBB3 authentication?
body: <p>Ok, this is a bit complicated, so bear with me.</p>
  
  <p>I'm running a PHPBB Forum for some time now and my goal is to create a Zend2 PHP Application using its User Administration and Authentication Features instead of building up a completely new Authorization component which would in turn need to synchronize with the Forum again.</p>
  
  <p><strong>Following Components will be used in the live environment:</strong> PHPBB3, Zend Framework 2 (latest stable), Apache, PHP 5.6+, MySQL running on a virtual Linux server without root access.</p>
  
  <p><strong>My Development Environment (running all examples below)is:</strong> PHPBB3, Zend Framework 2 (latest stable), XAMPP 3.2.2, PHP 5.6.21 with xdebug enabled, MariaDB running on Windows 8.</p>
  
  <p>Whenever integration of PHPBB is asked for the following lines inevitably turn up in searches:</p>
  
  <pre><code>global $phpbb_root_path, $phpEx, $user, $db, $config, $cache, $template;
  define('IN_PHPBB', true);
  $phpbb_root_path = './forum/phpBB3/'; // this path is from an external example
  $phpEx = substr(strrchr(__FILE__, '.'), 1);
  $phpBBFile = $phpbb_root_path . 'common.' . $phpEx;
  include($phpBBFile);
  
  // Start session management
  $user-&gt;session_begin();
  $auth-&gt;acl($user-&gt;data);
  $user-&gt;setup();
  </code></pre>
  
  <p>I have already had success including those without using a framework or by calling php directly through ajax, but now - using the Zend 2 Framework - there are multiple problems surfacing when including native PHPBB3 code.</p>
  
  <p>I have to say I am not an experienced PHP programmer and I have been learning about Zend for just a couple of days now.</p>
  
  <p>My first try centered on integrating the above code before the Zend Application is called in Zends <code>index.php</code>:</p>
  
  <pre><code>....
  // Setup autoloading
  require 'init_autoloader.php';
  
  global $phpbb_root_path, $phpEx, $user, $db, $config, $cache, $template;
  define('IN_PHPBB', true);
  $phpbb_root_path = 'public/forums/';
  $phpEx = substr(strrchr(__FILE__, '.'), 1);
  $phpBBFile = $phpbb_root_path . 'common.' . $phpEx;
  include($phpBBFile);
  
  // Run the application!
  Zend\Mvc\Application::init(require 'config/application.config.php')-&gt;run();
  ....
  </code></pre>
  
  <p>Resulting in this error:</p>
  
  <blockquote>
    <p>Catchable fatal error: Argument 1 passed to Zend\Stdlib\Parameters::__construct() must be of the type array, 
        object given, called in C:\xampp\htdocs\myZendApp\vendor\zendframework\zend-http\src\PhpEnvironment\Request.php 
        on line 72 and defined in C:\xampp\htdocs\myZendApp\vendor\zendframework\zend-stdlib\src\Parameters.php on line 24</p>
  </blockquote>
  
  <p>So calling PHPBB this early on seems to mess up Zend in a bad way I went on to other implementations.</p>
  
  <p>My favored design would include a separate Authentication Zend Module which handles PHPBB authentication and is available as a service for all routes and their controllers.
  Including and calling the phpbb scripts however lead to various problems probably related to the heavy use of globals.</p>
  
  <p>Here some example code from the <code>checkAction</code> in the <code>PhpbbAuthController</code>:</p>
  
  <pre><code>public function checkAction(){
      global $phpbb_root_path, $phpEx, $user, $db, $config, $cache, $template;
      define('IN_PHPBB', true);
      $phpbb_root_path = 'public/forums/';
      $phpEx = substr(strrchr(__FILE__, '.'), 1);
      $phpBBFile = $phpbb_root_path . 'common.' . $phpEx;
      include($phpBBFile);
  
      $user-&gt;session_begin();
      $auth-&gt;acl($user-&gt;data);
      $user-&gt;setup();
  
      $response = array();
      if ($user-&gt;data['user_id'] == ANONYMOUS) {
          $response['loginState'] = "logged_out";
      } else {
          $response['loginState'] = "logged_in";
      }
      return new ViewModel($response);
  }
  </code></pre>
  
  <p>And here the error from executing <code>session_begin()</code></p>
  
  <blockquote>
    <p>Fatal error: Call to a member function header() on null in 
        C:\xampp\htdocs\myZendApp\public\forums\phpbb\session.php on line 228</p>
  </blockquote>
  
  <p>After debugging into it it seemed that all references to the $request and $symfony_request inside those authentication functions where NULL.</p>
  
  <p>After sinking lots of hours into discerning a way to execute the scripts from Zend context I have set my eyes on a way to execute the scripts in a separate context. 
  The easiest way that came to my mind was to call the script from an <code>HttpClient</code> and use the Result text to drive my Authentication Service.
  To do that I would need to retrieve the session cookie from the called scripts and store it for use in the Zend application.</p>
  
  <p>If I channel the scripts through the Zend Framework I seem to run into the same problem again (having PHBB code in a Zend Controller), so I can't use Zends routing to access them.
  Since I am using an http request I have to store the scripts in the public directory or a subdirectory of it.</p>
  
  <p>And that is where I am right now. The internal call to the php files that use PHPBB work fine on their own, but the <code>HttpClient</code> I use (from a Zend Controller class for now) does run into a timeout at every turn, which I formulated into another question here: <a href="https://stackoverflow.com/q/37905866/2045820">Zend 2 Http Client Request times out when requesting php file from localhost/public directory</a>.</p>
  
  <p>I would appreciate your views, hints and possible architectures or even part solutions to my problem/s mentioned above.</p>
  
  <p>What I do not want to do under any circumstances is to invent my own authentication and user administration as it would always be inferior to the complex but proven system which is already in PHPBB and lead to security issues in the long run.
  Also the Zend application is considered an "Extra" since the Forum is the core of the site as things stand now. </p>
  
  <p>Thank you very much for your time and please ask for additional information. (I couldn't possible include all the code and I don't know what else would be relevant to you at this point)</p>