Here is the result:
- Code: Select all
define('IN_PHPBB', true);
$phpbb_root_path = '../forum/'; //Root to phpBB
$chat_root_phpbbrealtive_path = '../phpfreechat/'; //Root to chat relative to phpBB root ;)
include( $phpbb_root_path . 'extension.inc' );
include( $phpbb_root_path . 'common.' . $phpEx );
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
if ( !$userdata['session_logged_in'] ) //redirect to phpBB logon page if the user is not logged in
{
redirect(append_sid($phpbb_root_path . "login.$phpEx?redirect=" . $chat_root_phpbbrealtive_path . "index.$phpEx", true));
}
//
//classique phpfreechat parameter list
//
require_once "src/phpfreechat.class.php";
$params["serverid"] = md5(__FILE__);
$params["nick"] = iconv("windows-1251", "UTF-8", $userdata[username]);
Some comments to make things more clear:
1.
- Code: Select all
$phpbb_root_path = '../forum/';
path to the root of phpBB relative to the current file (index.php).
2.
- Code: Select all
$chat_root_phpbbrealtive_path = '../phpfreechat/';
path to the root of phpfreechat relative to phpBB root.
The sample assumes you have the following directory structure on your server:
..
/forum
/phpfreechat
3.
- Code: Select all
if ( !$userdata['session_logged_in'] ) //redirect to phpBB logon page if the user is not logged in
{
redirect(append_sid($phpbb_root_path . "login.$phpEx?redirect=" . $chat_root_phpbbrealtive_path . "index.$phpEx", true));
}
The code redirects user to the phpBB logon page if user is not logged in to the phpBB (in fact if user does not save his/her password inside phpBB). This page path (relative to phpBB root) is passed as 'redirect' param, so user will be redirected back to the PHPFreeChat's index.php after logging in to the phpBB.
4.
- Code: Select all
$params["nick"] = iconv("windows-1251", "UTF-8", $userdata[username]);
Do not forget to convert user names you got from phpBB to UTF-8 encoding, so the names are displayed correctly in the chat window.