1. First you need a copy of phpfreechat by going to http://www.phpfreechat.net/download/ and download it. When I wrote this, the latest version was v1.3.
2. At the very top of your phpfreechat index.php file, you need to put this code in:
Code: Select all
<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
if ($user->data['user_id'] == ANONYMOUS)
{
login_box('', $user->lang['LOGIN']);
}
?>
Make sure the variable $phpbb_root_path is correct. So if your forums are at example.com/forums and chat is at example.com/forums/chat, then PHPBB_ROOT_PATH should be ../ because you need to go back one directory. (As shown in the example code above).
If you don't want the script to redirect to the login page if you are not logged in, then take out this part:
Code: Select all
if ($user->data['user_id'] == ANONYMOUS)
{
login_box('', $user->lang['LOGIN']);
}
Code: Select all
$params["nick"] = "guest".rand(1,1000); // setup the intitial nickname
Code: Select all
$params["nick"] = $user->data['username_clean'];
Note: username_clean will take out any “weird” characters, including spaces and replace them with an underscore (_). It will also make capitals, lowercase. I chose username clean because it makes it easier to use the /kick and /ban command in phpfreechat. If you want the regular username to be shown, change:
Code: Select all
$user->data['username_clean']
Code: Select all
$user->data['username'];
If you also want your boards admins and global moderators to automatically be made a chat operator in chat (so you can kick and ban chat users if needed), then add this to your parameters in the index.php file:
Code: Select all
if ($user->data['group_id'] == 4 OR $user->data['group_id'] == 5) // Admins and Moderators
{
$params["isadmin"] = true; // Do what you want cause a pirate is free, you are a pirate ;)
}
http://example.com/forums/memberlist.php?mode=group&g=5
Take note of the &g= number in the url. That number is your admins group number. In this example, our admin group number is 5. Do the same for Global Moderators, in this example, our moderator group is 4.
In the end, this is how my index.php for phpfreechat looks after all the code is included and setup correctly.
Code: Select all
<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
if ($user->data['user_id'] == ANONYMOUS)
{
login_box('', $user->lang['LOGIN']);
}
?>
<?php
require_once dirname(__FILE__)."/src/phpfreechat.class.php";
$params = array();
$params["title"] = "Quick chat";
$params["nick"] = $user->data['username_clean'];
$params['firstisadmin'] = false;
if ($user->data['group_id'] == 4 OR $user->data['group_id'] == 5) // Admins and Moderators
{
$params["isadmin"] = true; // Do what you want cause a pirate is free, you are a pirate ;)
}
$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat
$params["debug"] = false;
$chat = new phpFreeChat( $params );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Chicken Talk Chat Room</title>
</head>
<body>
<div class="content">
<?php $chat->printChat(); ?>
</div>
</body></html>
Hope this helps people who want php free chat integrated with phpBB