phpBB API – Logging In And Logging Out a User

 

phpbb Logo

 

What is PHPBB3

phpBB is an open source forum software that is very easy to use and build communities. Most importantly it’s totally free.

phpBB3 provides an API that can be used to automatically login a user from a PHP script.

Although most of the phpBB API functions are documented, however their Wiki lacks examples and can be a little bit difficult to get started.

If you would like to synchronize your website with a phpBB forum, you can use the phpBB sessions to authenticate users.

Include The Following

define(‘IN_PHPBB’, true); //To be allowed to access the API files
$phpbb_root_path = ‘../phpBB3/’; //phpbb forum path
$phpEx = substr(strrchr(__FILE__, ‘.’), 1);
require_once($phpbb_root_path . ‘common.’ . $phpEx);
require_once($phpbb_root_path . ‘includes/functions_display.’ . $phpEx);

 

Logging in a User

function phpbbLogin($username, $password)
{
global $phpbb_root_path, $phpEx, $user, $auth;

$user->session_begin();
$auth->acl($user->data);

$auth->login($username, $password, true);

if($user->data[‘is_registered’]==1 && $user->data[‘user_type’] != USER_INACTIVE && $user->data[‘user_type’] != USER_IGNORE)
{
echo ‘User is logged in’;
}
}

 

Logging out a User

function phpbbLogout()
{
global $phpbb_root_path, $phpEx, $user;
$user->session_kill(false);
echo ‘User is logged out’;
}

Questions? Please ask!

Leave a Reply

Your email address will not be published. Required fields are marked *