Below is a detailed instructions how to integrate WordPress into phpBB so you can use the same login session. Users won’t have to login multiple times on the same site.
Accessing Member data from outside the forum or blog
In index.php or other designated root-level page, add the following lines of code:
define(‘IN_PHPBB’, true);
$phpbb_root_path = (defined(‘PHPBB_ROOT_PATH’)) ? PHPBB_ROOT_PATH : ‘/forums’;
$phpEx = substr(strrchr(__FILE__, ‘.’), 1);
include($phpbb_root_path . ‘common.’ . $phpEx);
include($phpbb_root_path . ‘includes/functions_display.’ . $phpEx);
$user->session_begin();
$auth->acl($user->data);
$user->setup(‘viewforum’);
Change “/forums” into the root path for your PHPBB3 installation.
Integrating Member Logout
Open ucp.php in the PHPBB3 installation.
Find: $message = ($user->data['user_id'] == ANONYMOUS) ? $user->lang['LOGOUT_REDIRECT'] : $user->lang['LOGOUT_FAILED'];}
After; find, in line:
meta_refresh(
Replace full code block with:
/* start PHPBB User mod */
if ( $_GET["s"] == ‘wp’ ) //Already logged out of wordpress
meta_refresh(2, append_sid(“{$phpbb_root_path}index.$phpEx”));
else
meta_refresh(0, append_sid(“../blog/wp-login.php?action=logout&s=phpbb”));
/* end PHPBB User mod */
Open wp-login.php in the WordPress installation. Find:
if ( isset( $_REQUEST['redirect_to'] ) )
$redirect_to = $_REQUEST['redirect_to'];
Replace with:
/* start PHPBB User mod */
if ( $_GET["s"] == ‘phpbb’ )
$redirect_to = “../forums/ucp.php?mode=logout&s=wp&sid=” .$_GET["sid"];
else
$redirect_to = ‘../forums/ucp.php?mode=logout&s=wp&sid=’ . $_GET["sid"]; //PHPBB User mod
/*
if ( isset( $_REQUEST['redirect_to'] ) )
$redirect_to = $_REQUEST['redirect_to'];
/* end PHPBB User mod */
Change ‘../forums/’ to your root PHPBB3 installation.
Integrating Member Logout, continued
Open functions.php in the WordPress installation. Find:
$html .= “</p><p>” . sprintf( __( “Do you really want to <a href=’%s’>log out</a>?”), wp_nonce_url( site_url(‘wp-login.php?action=logout’, ‘login’), ‘log-out’ ) );
wp_die( $html, $title);
Replace with:
elseif ( ‘log-out’ == $action ) { } //Do nothing, PHPBB User override
Open general-template.php in the WordPress installation. Find:
function wp_logout_url($redirect = ”) {
After, add:
global $phpbb_user; //PHPBB User mod
Find:
$redirect = “&redirect_to=$redirect”;
After, add:
$sid = ‘&sid=’ . $phpbb_user->data["session_id"]; //PHPBB User mod
Find:
return site_url(“wp-login.php$redirect”, ‘login’);
Replace with:
return “../forums/ucp.php?mode=login”; //PHPBB User mod
Change ‘../forums/’ to your root PHPBB3 installation.
Integrating Member Registration
Open functions_user.php in the PHPBB3 installation. Find:
$sql = ‘INSERT INTO ‘ . USERS_TABLE . ‘ ‘ . $db->sql_build_array(‘INSERT’, $sql_ary);
$db->sql_query($sql);
After, add:
/* start PHPBB User mod */
// WordPress user registration
$sql = “INSERT INTO wp_users (user_login, user_pass, user_nicename, user_email, user_url, user_registered,display_name)
VALUES (‘{$sql_ary["username"]}’, ‘{$sql_ary["user_password"]}’, ‘{$sql_ary["username"]}’,
‘{$sql_ary["user_email"]}’, ”, NOW(), ‘{$sql_ary["username"]}’)”;
$db->sql_query($sql);
/* end PHPBB User mod */
Integrating Member Login
Open index.php in your WordPress root folder.
Add, at the top of the page:
/* start PHPBB User Mod */
// Set for debugging
ini_set(‘display_errors’, 1);
error_reporting(E_ALL);
define(‘IN_PHPBB’, true);
$phpbb_root_path = (defined(‘PHPBB_ROOT_PATH’)) ? PHPBB_ROOT_PATH : ‘../forums/’;
$phpEx = substr(strrchr(__FILE__, ‘.’), 1);
include(“../forums/common.php”); //PHPBB common include file
require_once( dirname(__FILE__) . ‘/wp-load.php’ ); //Loads the needed WordPress include files
global $phpbb_user;
$phpbb_user = $user; //A copy of the PHPBB $user object
$phpbb_user->session_begin(); //Set up the PHPBB user session
if ( ! is_user_logged_in() ) { //Wordpress logged in
if( $phpbb_user->data["user_id"] != 1 ) { //PHPBB logged in
$credentials = array(‘user_login’ => $phpbb_user->data["username"],
‘user_password’ => $phpbb_user->data["user_password"],
‘remember_me’ => false);
wp_signon($credentials, false); //Sign into WordPress
header(“Location: index.php”);
}
}
/* end PHPBB User Mod */
Change “../forums/” to your root PHPBB3 installation.







