Integrating other sites with PHPBB

I have been working on integrating a PHPBB forum with an established site for a client. Their site has a pre-existing user base and sign-in method, and I didn’t want to disturb that.

This knowledge base article at details the basics of bringing PHPBB sessions into your other code. It includes common.php, which, if you read the source code, includes everything and the kitchen sink for PHPBB: general functions, template code, authenticaion/permissions code, etc. I decided to try to trim it down, as the only “feature” I needed from PHPBB on the main site was to keep a PHPBB session alive while the user used the main part of the website. This looks like more code than suggested in the PHPBB KB article, but it’s really less code overall, and it seems to work.

define(‘INPHPBB’, true);
rootpath = ’/somepath/’;
rootpath . '’);
rootpath . 'config.’.$phpEx);

sep = explode(’.’,$SERVER['REMOTEADDR’]);
$userip=sprintf(’%02x%02x%02x%02x’, $ipsep[0], $ipsep[1], $ipsep[2], $ipsep[3]);

rootpath . 'includes/constants.’.$phpEx);
rootpath . 'includes/sessions.’.$phpEx);
rootpath . 'includes/db.’.$phpEx);

$strSQL = “SELECT config
name, configvalue FROM ” . CONFIGTABLE . “ WHERE configname IN ('cookiename’, 'cookiepath’, 'cookiedomain’, 'cookiesecure’, 'sessionlength’);”;
if( !($result = $db->sqlquery($strSQL)) ) {
die('Could not query config information’);
while ( $row = $db->sql
fetchrow($result) ) {
$boardconfig[$row['configname’]] = $row['configvalue’];

$userdata = array();
$userdata = session
pagestart($userip, PAGEINDEX);

This method is working OK for me so far. I’ve got several other steps to really get things integrated. One problem is that the existing site’s code uses a global variable to access the database known as $db, and guess what, so does PHPBB, but they’re not compatible. :(

I’m also toying with the idea of stripping out PHPBB’s existing session code and replacing it with my own which will connect the main site and the forum. I need to see how well PHPBB’s session code is written and if it’s mostly separated from the rest of the PHPBB code. But you might give this code a shot if you want to work with PHPBB’s sessions.

Update 2006-04-12: I had to update this code to work with PHPBB 2.0.20. I also changed the PHPBB message_die() function to PHP’s die() function since I’m not including it from the PHPBB functions.