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?
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?
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
}
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.
$user->session_kill(); $user->session_create($newUserID, false, true); $auth->acl($user->data);
I'm using this to switch to an anonymous user (userid=1) before my script does some automatic posting, then switching back to the original user (whos userid I have stored before making the switch). –
Wurster 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
}
In your PHP script that's crawling through HTML will need to :
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 :
© 2022 - 2024 — McMap. All rights reserved.
$user_id
. – Elwood