Search code examples
phpmysqlintegrationphpbb

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?


Solution

  • 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
    }