I recently had the need to use PHPbb3 and CodeIgniter together and wanted to use PHPbb’s authentication to make things easy.
I made a little library to help with that implementation:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* PHPbb CI Auth Class
*
* Authentication library for CodeIgniter that integrates with PHPbb (Use PHPbb's authentication system inside your CI apps)
*
* @author Ryan Pharis
* @version 0.1
* @link http://ryanpharis.com
* @credits Modified code from http://www.mrkirkland.com/adding-a-user-to-phpbb3-from-an-external-script
*/
class Phpbb_ci_auth
{
function Phpbb_ci_auth()
{
define('IN_PHPBB', true);
//set scope for variables required later
global $phpbb_root_path;
global $phpEx;
global $db;
global $config;
global $user;
global $auth;
global $cache;
global $template;
//your php extension
$phpEx = substr(strrchr(__FILE__, '.'), 1);
$phpbb_root_path = './forums/';
//includes all the libraries etc. required
require($phpbb_root_path .'common.php');
$user->session_begin();
$auth->acl($user->data);
$this->user_data = $user->data;
$this->ci =& get_instance();
log_message('debug', 'PPHbb CI Auth Initialized');
}
function check_permissions()
{
if (!$this->is_logged_in()) {
ci_redirect('forums/ucp.php?mode=login','location');
}
if (!$this->is_admin()) {
$this->ci->session->set_flashdata('message', 'NO SOUP FOR YOU!');
ci_redirect('','location');
}
}
function is_admin()
{
if ($this->user_data['group_id'] == 5) {
return true;
}
}
function is_logged_in()
{
if ($this->user_data['group_id'] == 2 || $this->user_data['group_id'] == 3 || $this->user_data['group_id'] == 4 || $this->user_data['group_id'] == 5) {
return true;
}
}
function get_user_data()
{
return $this->user_data;
}
} //end Class Phpbb_ci_auth
The only problem I ran into was that phpbb uses a function called “redirect” and as you know, CI has a redirect function in the url helper. So, as a compromise, I changed the CI code to ci_redirect() and just have to remember to change that upon upgrading to a new CI version.
I have my phpbb install under a directory within my CI site (on the same level as application) and called it “forums” so if you have a different folder name that you place phpbb in, just change that in the constructor for $phpbb_root_path.
Just thought I’d put that up there if anyone needs or wants to use phpbb inside of CI.
- Ryan Pharis
