Summary: Integrate phpFreeChat (PFC) ajax chat into PmWiki
Version: 2007-07-09
Status: Young and ugly
Maintainer: lordmundi
Categories: Chat Integration Ajax

Questions answered by this recipe

This section is optional; use it to indicate the types of questions (if any) this recipe is intended to answer.

  • How can I integrate an ajax based chat room into pmwiki?
  • How can I integrate php Free Chat into pmwiki?


This recipe will integrate a phpFreeChat instance into a wiki page for ajax based chat.


I am actually embarrassed at the state of this recipe. The only reason I decided to throw it up here is because I thought someone else with more pmwiki/php/ajax experience might be able to solve the problems I encountered that I ultimately had to hack through. More info in the comments at the bottom.

But, I should add... it works! (my computer science teacher would hate to hear me say that). Right now it supports all of the chat room features and settings and also automatically sets the nickname based off of the Author/AuthId variable. If you aren't requiring or using the Author variable, you can just it let it grab "guest" nicknames for people and let them change them themselves.

For a demo of phpfreechat, see


  1. Download phpFreeChat from (I used version 1.0-beta11)
  2. Unzip the contents of the tar file in your pub dir
  3. chmod the writeable dirs
    • chmod 777 pub/phpfreechat-1.0-beta11/data/private
    • chmod 777 pub/phpfreechat-1.0-beta11/data/public
  4. Copy phpfreechat_pmwiki.phpΔ into your cookbook dir.
  5. Copy phpfreechat_pmwiki_markup.phpΔ into your cookbook dir.
  6. Add include_once("$FarmD/cookbook/phpfreechat_pmwiki.php"); to config.php (somewhere above the authuser inclusion!!)
  7. Add include_once("$FarmD/cookbook/phpfreechat_pmwiki_markup.php"); either to config.php, or a per-page or per-group customization config file. For example, I put the link in "local/Main.Chat.php" because I only want the chat markup to be processed on that single page.
  8. Add the markup (:phpfreechat:) where you want the chat room to appear


NOTE: After changing anything in the config, you will need to "rehash" the config. This can be done by becoming an admin user, running the "/identify" command, and then issuing the "/rehash" command. Or, my personal favorite, just deleting everything in the "phpfreechat/data/private/" dir (make sure that "private" is still writable after you clean it out). More details about this on the phpfreechat website.

Sets the dir to point to the PFC installation (defaults to "$FarmD/pub/phpfreechat-1.0-beta11")
Tells whether or not to try and use the nasty hack workaround to override the nick in the chat room with that from authuser (defaults to true). This is all from some difficulties with the integration that I'm hoping other can fix. Details below.
This is the main configuration array for phpfreechat. I am only overriding a couple of parameters. The rest are all defaulted inside PFC (but all elements are easily overwritten by setting them before inclusion of the recipe exactly like the parameters above). The few defaults I try to set for users are:
SDVA($pmwiki_PFC_params, array(
  'nick'         => "guest".rand(1,10000),
  'title'        => "$WikiTitle chat",
  'serverid'     => md5($pmwiki_PFC_Group)
  • The nick is a random guest label that gets overwritten later if enabled.
  • The title just appends " chat" to your existing $WikiTitle (as long as you include the recipe after you set that in your config.php).
  • The serverid is the group name of the current page. Basically, the serverid is a unique tag that identifies each chat room. By defining like this, I have defaulted the config so that chat rooms in separate groups will automatically become different chat rooms. Want to make all chat rooms belong to the same one? Just change this to a string like "md5(__FILE__)" which will be the same no matter what page you are on. I did it this way because I thought users might want for each group to have its own chat room. You could easily set it to have a differnt one for every page as well... just use "md5($pagename)" (I think, I haven't tried this).
  • There are lots of other configuration options that you can set such as theme selection, size, clock display, timeouts, etc.. They are all detailed here:

A sample configuration of some parameters:

$pmwiki_PFC_params = array(
  'admins'       => array( 'admin' => '', 'bob' => ''),
  'max_msg'      => 0,
  'height'       => "300px",

Recommended Use

Since you probably don't want users creating their chat rooms, you should probably lock down the markup to a specific page as I explained above.

Also, phpfreechat is known to be pretty heavy on servers, so if you have a site with lots of traffic, you may want to investigate something else.

Release Notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

  • 2007-07-09: First, quick and dirty release.


Quite frankly... I hate this integration that I've done, but hopefully someone else will fix it up.

It all started looking at the simple demos/examples on the phpfreechat site. They look extremely easy. Integrating it into pmwiki turned into a 2 week headache though. The main thing I wanted to do is create a markup to instantiate the chat box (this was easy enough) and have it use $Author or $AuthId as the nick name in the chat.

One problem is with sessions. After much searching, it looks like the sessions that PFC uses conflicts with the sessions for authuser. This is why I have to include it before authuser. And if I include it before authuser, I can't know the $AuthId. This is why I split up the recipe into two parts.

Another problem seems to be how late in the processing the script can go. Putting all of the recipe in the "Main.Chat.php" seemed to screw things up as well.

So what am I so embarrassed about? Well, when you instantiate the phpfreechat class, the "nick" parameter is already set. You can see we are setting it to "guest" + a random number up above since we don't know the author name at that point. The nasty part is once we process the markup and are going to generate the javascript to place in the html to connect, I actually parse through the output before I return it to pmwiki and change the nickname to the author name.

This is not only ugly, and wrong, but it also has disadvantages. Doing it this way doesn't let me use the "frozen_nick" option to keep people from changing their nick. So, this lets people set their nick to whatever they want. This also means you should set an admin password so people can't change to the admin chat user and do what they want.

I would love to hear people's experiences with this. -- lordmundi July 10, 2007, at 12:43 AM

FYI, here are some of the posts on the PFC forum that I posted, but didn't help me much:

Question: I'm still looking into a good chat system and am curious to if anyone has any screenies of this or maybe another chat implementation. Chris July 16, 2024, at 08:47 PM
Answer: Successful implementation of third-party PHP code: PHPFreeChat-Users M.L. Denning July 16, 2024, at 08:47 PM

It's worth noting that phpFreeChat has 2 versions, and v.2 is rather different from v.1. v.2 is more of a fork of v.1, not an upgrade. This recipe is based on v.1, which I have learned to hate. I have used v.2 for quite some time (months) without issue. I learned 1-31-12 that this recipe exists, and I intend to try this with v.2. I'll post back any issues.

 1. you hard coded their path, with their folder name. Their folder name, however, includes their version. To use a different version, I either have to rename my folder to what you called it in line 38 of <phpfreechat_pmwiki.php>, which is "phpfreechat-1.0-beta11", or I have to find all references to this folder in your code and change them to something sane, like "phpfreechat", which is what I'll do (since I suspect this is the only place it's referenced in your code).

 2. I've seen your comment on their random name assignments. I am about to run v.2 under pmwiki 2.2.35. if I never post again, this is a bad idea and you should probably not try.
 2a. I survived, but never get past "chat loading". This I will explore later.  

v.2 requires some $params = array();, which I don't think v.1 uses. A serious bit of coding is ahead.

Note to self: If you set up phpfreechat in one folder, use it, and then just copy it to another, expect file permission errors until you refresh a few times to clear cache.

See Also


User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.