0

まだ完全な解決策が見つからない問題に遭遇しました。まず、シナリオの概要を説明します。サーバー上に PHPBB3 フォーラムがあり、フォーラムにリンクされている同じサーバー上に (私が開発した) アプリケーションもあります。アプリケーションは、フォーラムにログインしている場合にのみアクセスできます。また、特定のフォーラム ユーザー グループに属している場合にのみ、アプリケーションの一部にアクセスできます。また、アプリは、ユーザーがスクリプト/ページにアクセスしたときに、専用ユーザー (「ボット」と呼びましょう) を介してプログラムでフォーラム スレッド/投稿を投稿できる必要があります。1.現在ログインしているユーザーを保存します(彼を「テストユーザー」と呼びましょう) 2.ユーザー「ボット」でログインします 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;

}

役立つヒントや別の方法を教えていただければ幸いです。

4

1 に答える 1

0

セッションなどをそのままにしておくことをお勧めします。

CURL を使用して「ボット」アクティビティを開始すると、現在のユーザーのコンテキスト内ではなく、舞台裏で対話します。たとえば、作成された投稿の IP アドレスは、ユーザーの IP アドレスではなく、サーバーの IP アドレスになります。

于 2010-02-01T04:46:14.387 に答える