0

我将 phpbb3 集成到我的网站中。当用户登录我的网站时,会有一个名为论坛的选项卡。如果他点击论坛,它将进入一个页面,要求用户名和密码登录。但是我希望当用户点击论坛时,他必须直接使用他的帐户详细信息进入论坛,而无需再次登录。

请帮我......

4

1 回答 1

0

我实际上做了同样的事情,一个用户在我的网站上注册,同时我也会自动为他们创建一个 phpbb 帐户。

这是我用来注册它们的代码(我不使用 phphash 函数作为密码,我使用我的散列函数。密码的 md5 散列实际上是散列一个已经散列的密码):

//Register the user on the forum code

global $phpbb_root_path, $phpEx, $user, $db, $config, $cache, $template,$auth;             

 define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './Forums/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
require('./Forums/includes/functions_user.php');

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('viewtopic');

$user_row = array(
     'username'                => $username,                //REQUIRED IN FORM
     'user_password'           => md5($password_1),            //REQUIRED IN FORM
     'user_email'              => $email,            //REQUIRED IN FORM
     'group_id'                => 2,//(int) $group_id,
     'user_timezone'           => $timezone = date(Z) / 3600,//(float) $data[tz],
     'user_dst'                => date(I),//$is_dst,
     'user_lang'               => $user->lang_name,//$data[lang],
     'user_type'               => USER_NORMAL,//$user_type,
     'user_actkey'             => '',//$user_actkey,
     'user_ip'                 => $user->ip,
     'user_regdate'            => time(),
     'user_inactive_reason'    => 0,//$user_inactive_reason,
     'user_inactive_time'      => 0,//$user_inactive_time,
);


 //Register user on the forum
 $forum_user_id = user_add($user_row);

 return "both_registered";

然后登录他们我使用这个:

//Now log them into the forum
global $phpbb_root_path, $phpEx, $user, $db, $config, $cache, $template, $auth;             

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : getcwd().'/Forums/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
require(getcwd().'/Forums/includes/functions_user.php');

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

// Begin phpBB login
if(!$user->data['is_registered'])
{
  $username = $username;
  $password = $password;
  $autologin = 1;

  $result = $auth->login($username, $password, $autologin);
  //print_r($result);
}

显然你可能需要稍微改变一下,在注册或登录之前我做了很多检查。希望这会有所帮助,如果有人看到我做的不对,请告诉我。

于 2014-10-21T21:14:04.340 回答