问题
I am trying to create topics in phpBB3 forums by a php file.
I found this
Creating a forum in phpBB3 from PHP and settings permissions
But when i copy this and running my php file i am getting this
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
I also found this
https://wiki.phpbb.com/Using_phpBB3%27s_Basic_Functions
After that i wrote this code:-
<?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));
?>
But no topics is created in forum. I also checked 'phpbb_topics' and phpbb_posts table my data is not inserted there.
回答1:
Got it.
We need to add these piece of code at the top of the script and need to remove our extra 'require_once'.
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();
来源:https://stackoverflow.com/questions/31626221/create-topic-in-phpbb3-by-php-file