我试图通过php文件在phpBB3论坛中创建主题。
我发现了这个
Creating a forum in phpBB3 from PHP and settings permissions
但是当我复制这个并运行我的php文件时,我得到了这个
PHP Notice: Use of undefined constant FORUMS_TABLE - assumed 'FORUMS_TABLE' in /var/www/html/phpvibe/forum/insertPhpbb.php on line 13
PHP Fatal error: Call to a member function sql_build_array() on a non-object in /var/www/html/phpvibe/forum/insertPhpbb.php on line 14
我也找到了这个
https://wiki.phpbb.com/Using_phpBB3%27s_Basic_Functions
之后我写了这段代码: -
<?php
require_once("/var/www/html/phpvibe/forum/includes/functions.php");
require_once("/var/www/html/phpvibe/forum/includes/functions_posting.php" );
// note that multibyte support is enabled here
$my_subject = "test";
$my_text = "testdata";
// variables to hold the parameters for submit_post
$poll = $uid = $bitfield = $options = '';
generate_text_for_storage($my_subject, $uid, $bitfield, $options, false, false, false);
generate_text_for_storage($my_text, $uid, $bitfield, $options, true, true, true);
$data = array(
'forum_id' => 2,
'icon_id' => false,
'enable_bbcode' => true,
'enable_smilies' => true,
'enable_urls' => true,
'enable_sig' => true,
'message' => $my_text,
'message_md5' => md5($my_text),
'bbcode_bitfield' => $bitfield,
'bbcode_uid' => $uid,
'post_edit_locked' => 0,
'topic_title' => $my_subject,
'notify_set' => false,
'notify' => false,
'post_time' => 0,
'forum_name' => '',
'enable_indexing' => true,
);
print_r(submit_post('post', $my_subject, '', POST_NORMAL, $poll, $data));
?>
但是在论坛中没有创建主题。我还检查了'phpbb_topics'和phpbb_posts表,我的数据没有插入那里。
答案 0 :(得分:0)
知道了。
我们需要在脚本顶部添加这些代码,并且需要删除我们额外的&#39; require_once&#39;。
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.') , 1);
error_reporting(0);
include ($phpbb_root_path . 'common.' . $phpEx);
include ($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
$user->setup();