Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically log in into phpBB forum?

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?

like image 491
Tom Smykowski Avatar asked Nov 10 '11 13:11

Tom Smykowski


2 Answers

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.

like image 63
igorw Avatar answered Sep 20 '22 21:09

igorw


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
}
like image 36
nickb Avatar answered Sep 23 '22 21:09

nickb