Integrating other sites with PHPBB 2.0.20

In a previous entry, I detailed how I used some code from PHPBB to integrate its session management with my existing website. The idea is to include just enough PHPBB stuff to get PHPBB sessions working, and nothing else. Due to some session code changes introduced in the PHPBB update to version 2.0.20, I had to change the code some. Here is how it looks now:

define(‘IN_PHPBB’, true);
$phpbb_root_path = ’/somepath/’;
include($phpbb_root_path . 'extension.inc’);
include($phpbb_root_path . 'config.’.$phpEx);

$ip_sep = explode(’.’,$_SERVER['REMOTE_ADDR’]);
$user_ip=sprintf(’%02x%02x%02x%02x’, $ip_sep[0], $ip_sep[1],
   $ip_sep[2], $ip_sep[3]);

include($phpbb_root_path . 'includes/constants.’.$phpEx);
include($phpbb_root_path . 'includes/sessions.’.$phpEx);
include($phpbb_root_path . 'includes/db.’.$phpEx);

$strSQL = “SELECT config_name, config_value FROM ” . CONFIG_TABLE .
   “ WHERE config_name IN ('cookie_name’, ” .
   “'cookie_path’, 'cookie_domain’, 'cookie_secure’, ” .
   “'rand_seed’, 'session_length’);”;

if( !($result = $db->sql_query($strSQL)) ) {
   die('Could not query config information’);
}
while ( $row = $db->sql_fetchrow($result) ) {
   $board_config[$row['config_name’]] = $row['config_value’];
}

$userdata = array();
$userdata = session_pagestart($user_ip, PAGE_INDEX);


In addition, I had to copy the dssrand() function out of PHPBB’s includes/functions.php file into my startup-script. I think that’s preferable to including the whole block of functions, but that’s another option. You have also have to modify the messagedie() function inside dss_rand() because I’m not including that function. I just used PHP’s die() function and only included the text of the error, not the PHPBB specific parameters.

Update 2006-07-17: This code is OK for PHPBB 2.0.21 also.