我遇到了一个尚未找到完美解决方案的问题。首先让我概述一下场景。我在服务器上有一个 PHPBB3 论坛,在链接到论坛的同一台服务器上还有一个应用程序(由我开发)。该应用程序只有在您登录到论坛时才能访问,并且它的某些部分只有在您位于特定论坛用户组中时才能访问。此外,当用户访问脚本/页面时,应用程序需要能够通过专用用户(我们称之为“机器人”)以编程方式发布论坛线程/帖子。所以我需要的是: 1. 保存当前登录的用户(我们称他为“测试用户”) 2. 使用用户“Bot”登录 3. 发布线程/帖子。4. 销毁会话 5. 恢复登录用户
这种“排序”起初有效,但当反复调用/发布时,前 1-2 个帖子将由“机器人”发布,但以下内容将由“测试用户”发布。当前代码:
这是在 setup.php 中,它包含在所有相关脚本中。
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
// The common.php file is required.
include($phpbb_root_path . 'common.' . $phpEx);
// this is required for auto posting
include($phpbb_root_path . 'config.' . $phpEx);
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
这是函数本身,在另一个脚本中
require_once 'setup.php';
function create_forum_post($subject, $text, $forumid, $posting_userid, $topic_id=NULL) {
if(!PHPBB_SESSION_INTEGRATION) return false;
global $user, $auth;
$username = BOT_USERNAME;
$password = BOT_PASSWORD;
$title = unhtmlentities( $subject );
$text = unhtmlentities( $text );
$forumid = $forumid;
$topicid = $topic_id;
$original_user_id = $user->data['user_id'];
$user->session_begin();
$login = $auth->login($username, $password, false);
$auth->acl($user->data);
$user->setup();
$title = utf8_normalize_nfc($title);
$text = utf8_normalize_nfc($text);
$poll = $uid = $bitfield = $options = '';
generate_text_for_storage($title, $uid, $bitfield, $options, false, false, false);
generate_text_for_storage($text, $uid, $bitfield, $options, true, true, true);
$data = array(
'forum_id' => $forumid,
'topic_id' => $topicid,
'icon_id' => false,
'post_approved' => true,
'enable_bbcode' => true,
'enable_smilies' => true,
'enable_urls' => true,
'enable_sig' => true,
'message' => $text,
'message_md5' => md5($text),
'bbcode_bitfield' => $bitfield,
'bbcode_uid' => $uid,
'post_edit_locked' => 0,
'topic_title' => $title,
'notify_set' => false,
'notify' => false,
'post_time' => 0,
'forum_name' => '',
'enable_indexing' => true,
);
if ($topicid == NULL)
$post_url = submit_post('post', $title, '', POST_NORMAL, $poll, $data);
else
$post_url = submit_post('reply', $title, '', POST_NORMAL, $poll, $data);
$user->session_kill();
$user->session_create($original_user_id, false, true);
return $post_url;
}
我会很感激任何有用的提示或替代方法。