Take the 2-minute tour ×

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?

share|improve this question

3 Answers 3

up vote 7 down vote accepted

You will need a script that integrates with the phpBB framework. Something like this should work.

define('IN_PHPBB', true);

// Start session management

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

    // Logged in
    // Something went wrong
share|improve this answer

First you need to bootstrap for phpBB:

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './phpBB/';


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.

share|improve this answer
This doesn't answer the OP's question, as your solution is not accepting the user's username/password to log them in, but forcing a login of a specfic $user_id. –  nickb Nov 10 '11 at 14:13
Fair enough, I did go a bit too far into the details. I'll leave my answer here anyway, since I put some effort into it. Might help someone someday. –  igorw Nov 10 '11 at 14:39
I agree, it is useful if you already have their ID. –  nickb Nov 10 '11 at 19:09
I know that's quite late, but thanks a lot for taking the decision to leave the answer, because that's the only place I've found a solution to how to login users using only the user ID and not the password. –  TheNavigator Feb 5 '14 at 9:25

In your PHP script that's crawling through HTML will need to :

  • POST data like if it was filling in the form
  • Get the answer from the server ; probably extract the session's cookies
  • Send those cookies for subsequent requests

You might be interested in using some already-existing library to facilitate that.
For instance, you can take a look at Zend_Http_Client (see also ; the part about Sending Multiple Requests With the Same Client will probably interest you ;-) )

You might also want to take a look at some other questions/answers, like :

share|improve this answer
Not really sure how this has to do with phpBB? –  nickb Nov 10 '11 at 14:02
The question was: "How to programmatically log in into phpBB forum?". This is a good general answer explaining that. –  budwiser Nov 10 '11 at 14:40
@budwiser - The question was how to login to phpBB, not how to generally log into any remote web application. So, it's not well-suited for phpBB, especially when there's an API available and this answer is talking about crawling HTML and remote authentication. (The OP's question clearly states the need for a local authentication solution) –  nickb Nov 10 '11 at 19:17

Your Answer


