I have a forum using phpBB. Now i would like to do something like this from source code:
login("user", "password")
How to do this in phpBB?
First you need to bootstrap for phpBB:
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './phpBB/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
$user->session_begin();
You'll have to replace the ./phpBB/
part with the relative path to the forum.
To make the user logged in, you have to do:
$result = $user->session_create($user_id, $admin, $autologin, $viewonline);
$admin
should probably be false
, $autologin
and $viewonline
depend on what you want.
NOTE: Calling session_create
will set the session cookie for the user, so make sure you only call that when the current request is actually serving that user.
You will need a script that integrates with the phpBB framework. Something like this should work.
<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
?>
Then, look at the $auth->login() function (an example use is in the login_box()
function in /includes/functions.php
). A simplistic yet incomplete example is:
$result = $auth->login($username, $password); // There are more params but they're optional
if ($result['status'] == LOGIN_SUCCESS)
{
// Logged in
}
else
{
// Something went wrong
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With