Advanced configuration

This page is for 1.x phpfreechat versions. For 2.x versions, check the documentation

Setup the parameters

The chat is usable using the default configuration but a lot of options can be tweaked to customize the chat. For example, to change the refresh speed to 2 seconds, copy/paste this piece of code and run ”/rehash” command:

  <?php
 
  require_once "src/phpfreechat.class.php"; // adjust to your own path
  $params["serverid"]      = md5(__FILE__);
  $params["refresh_delay"] = 2000; // 2000ms = 2s
  $chat = new phpFreeChat($params);
 
  ?>
 
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html>
    <head>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
      <title>phpFreeChat demo</title>
    </head>
    <body>
      <?php $chat->printChat(); ?>
    </body>
 
  </html>

Another example: to set the initial nickname to “guest” (it can be useful when the chat is integrated into a portal or a forum which provides the login/password), copy/paste this piece of code:

  <?php
 
  require_once "src/phpfreechat.class.php"; // adjust to your own path
  $params["serverid"] = md5(__FILE__);
  $params["nick"]     = "guest"; // it can be useful to take nicks from a database
  $chat = new phpFreeChat($params);
 
  ?>
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html>
    <head>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
      <title>phpFreeChat demo</title>
    </head>
 
    <body>
      <?php $chat->printChat(); ?>
    </body>
  </html>

Thanks to these two examples, you should understand how to setup the chat using the parameters:

$params["param-name"] = "param-value";

As parameters are stored in a cache, be sure to run /rehash command each time you change a parameter value.

Now have a look to the global parameters list and to the proxies parameters list.

Directories structure recommendation

Here is some recommendations about how to deploy and integrate the chat in an existing project. Following these recommendations will facilitate future chat upgrades.

Firstly, I suppose your Web server root directory is www/ (where all your existing project files are located). Then download and extract latest phpfreechat version in this directory, the directories hierarchy should have the look of this figure:

  1. The phpfreechat raw sources : contains the unmodified phpfreechat sources (never modify it so it will be easier to upgrade next version). To have these files, just download the phpfreechat zip (or tar.gz for linux users) archives from the download page.
  2. Your chat script : this script contains your customized chat parameters list. You also have to require_once the phpfreechat.class.php from your phpfreechat sources. Here is a sample chat.php files for the above example:
        <?php
        require_once dirname(__FILE__).'/phpfreechat-1.0-beta8/src/phpfreechat.class.php'; // adjust to the correct path
        $params["serverid"] = md5(__FILE__); // used to identify the chat
        $chat = new phpFreeChat($params);
        ?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
               "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html>
          <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8" />
            <title>Chat</title>
          </head>
          <body>
            <?php $chat->printChat(); ?>
          </body>
        </html>
  3. Your other website files : just ignore this point if you just want to have a chat on your website. However maybe you would like to have other scripts in your website ? (ex: forum, registration system, blog) then just put these files here.
Fork me on GitHub