PHPBB 3 Login Integration

This script will enable you to have a universal website login that will also log a user into your phpbb forum. There is also a logout function. PHPBB must be running in md5() for passwords.


<?
//----------------------------------------------------
//Logout to website and phpbb
//----------------------------------------------------
if(isset($_REQUEST['logout'])){

//Perform your website logout and then...

	define('IN_PHPBB', true);
	//Make sure to change the path to reflect your install of phpbb
	$phpbb_root_path = "forum/";
	$phpEx = "php";
	
	include($phpbb_root_path."common.php");

	$user->session_kill();
	$user->session_begin();
}

//----------------------------------------------------
//Login of website and phpbb
//----------------------------------------------------
if($_POST['username']!='' && $_POST['password']!=''){

//Perform your website login and then...

	define('IN_PHPBB', true);
	//Make sure to change the path to reflect your install of phpbb
	$phpbb_root_path = "forum/";
	$phpEx = "php";
	
	include($phpbb_root_path."common.php");
	
	$user->session_begin();
	$auth->acl($user->data);
	$user->setup('ucp');

	$password	= request_var('password', '', true);
	$username	= request_var('username', '', true);
	$autologin	= (!empty($_POST['autologin'])) ? true : false;
	$viewonline = (!empty($_POST['viewonline'])) ? 0 : 1;
	$admin 		= ($admin) ? 1 : 0;
	$viewonline = ($admin) ? $user->data['session_viewonline'] : $viewonline;
	if ($admin && utf8_clean_string($username) != utf8_clean_string($user->data['username']))
		{
			add_log('admin', 'LOG_ADMIN_AUTH_FAIL');
			trigger_error('NO_AUTH_ADMIN_USER_DIFFER');
		}
	$result = $auth->login($username, $password, $autologin, $viewonline, $admin);

}
?>

Associated Files

Comments

Log in to comment