How to integrate phpbb forum login
I have had to install phpbb forum on a website that already had a user table and I want to…
I have had to install phpbb forum on a website that already had a user table and I want to keep the users of my table as the only users of the web site. I want to give to my users the access to the phpbb functionalities.
I’ve searched for a ready-to-use component but it seems that it doesn’t exists. I’ve tried to watch the source of phpbb to understand if changing the whole code to match my table was a valid path to run, but it seems to be too complex, there are too many occurrence of the user table in the code. So I’ve tried to understand if mapping records could be a solution and I’ve found many people that walk this way. I’ve found a Php class that does some of the work mapping users but it wasn’t enough, so here is my 10 steps tutorial.
STEP 1: install phpbb forum (i’ve used version 3)
Read documentation of phpbb on how to install the forum, it’s quite easy, there is a good wizard. For the admin user choose a username that is an admin on your user table so the mapping will be correct.
STEP 2: download this phpbbintegration.class.php [download]
This class does a relevant job: it allows you to copy your users from your community into phpbb tables.
It also does the update password and something more:
<? /* PHPBB3 Integration class ================================================================================= this class is based on the work of Jonathan Gibb, http://www.polr.co.uk and modified by Giulio Pons https://www.barattalo.it to handle also the login process. A complete tutorial can be found here:How to integrate phpbb forum login* Functionality: * -------------- * Add a user to PHPBB3 * Change users password on PHPBB3 * Disable/ban user on PHPBB3 * Enable/un-ban user on PHPBB3 ================================================================================= */ // CONFIG // ====== define('ROOT_PATH', "../forum/"); // map this dir to your own installation of phpbb define('IN_PHPBB', true); if (!defined('IN_PHPBB') || !defined('ROOT_PATH')) exit(); $phpEx = "php"; $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : ROOT_PATH . '/'; include($phpbb_root_path . 'common.' . $phpEx); $user->session_begin(); $auth->acl($user->data); $user->setup(); class Phpbb3Integration { var $table_prefix; var $connection; var $lang; var $default_timezone; var $user_dst; var $user_dateformat; var $user_colour; function Phpbb3Integration($table_prefix = 'phpbb_') { // CONFIG // ====== $this->lang = "it"; // language, I've tried "it" and "en" $this->default_timezone = "1.00"; // +1 hour $this->user_dst = 1; // use legal time $this->user_dateformat = "|d/m/Y|, G:i"; // date format $this->user_colour = "9E8DA7"; // user colour $this->table_prefix = $table_prefix; } function connect($server,$dbuser,$dbpass,$dbname) { $this->connection = mysql_connect ( $server, $dbuser, $dbpass ); if (!$this->connection) return false; if (!mysql_select_db ( $dbname, $this->connection )) return false; return true; } function addNewUser($username,$password,$email,$ip) { $sql = $this->createSqlToAddUserRow ( $username, $password, $email, $ip ); mysql_query ( $sql, $this->connection ); $id = mysql_insert_id ( $this->connection ); $sql = $this->createSqlToAddUserGroupRow ( $id ); mysql_query ( $sql, $this->connection ); } function changeUserPassword($username,$password) { $sql = $this->createSqlToUpdateUserPassword ( $username, $password ); mysql_query ( $sql, $this->connection ); } function disableUser($username) { // first get phpbb internal id for username $sql = "select user_id from " . $this->table_prefix . "users where username = '$username'"; $query = mysql_query ( $sql, $this->connection ); if (! $query) return false; $id = mysql_result ( $query, 0 ); // create ban row $banSql = "insert into " . $this->table_prefix . 'banlist (ban_userid, ban_start, ban_reason, ban_give_reason)'; $banSql .= "values ('$id','" . time () . "', 'External Integration','Banned by External Integration')"; mysql_query ( $banSql, $this->connection ); } function enableUser($username) { // first get phpbb internal id for username $sql = "select user_id from " . $this->table_prefix . "users where username = '$username'"; $query = mysql_query ( $sql, $this->connection ); if (! $query) return false; $id = mysql_result ( $query, 0 ); // delete ban row $deleteSql = "DELETE FROM " . $this->table_prefix . 'banlist where ban_userid = ' . $id; $query = mysql_query ( $deleteSql, $this->connection ); return ($query != false); } // Helper Methods // ============== /** * Generate salt for hash generation */ function _hash_gensalt_private($input,&$itoa64,$iteration_count_log2 = 6) { if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) $iteration_count_log2 = 8; $output = '$H
