November 28, 2006

PHP guestbook for

Filed under: PHP,Programming,T3city — pj @ 12:20 am

When T3city took over the hosting for, they had a guestbook on their web site. Their old host used what appeared to be a custom guestbook written in Cold Fusion. We don’t support Cold Fusion and I figured I could find something better in PHP, anyway. I found and installed the Purple Yin Guestbook. The PYG script worked well for some time. At some point, though, their guestbook (and guestbooks all over the Internet) got hit by bots (autonomous programs) created by spammers to post in guestbooks. Because the posts were automated, there were many of them. Eventually,’s owner, Gary, called and we discussed the spam problem. I decided to upgrade to the latest version of PYG. This new version supported captcha images. Gary asked to only use one random digit for the captcha image. This stopped the spam right away. Unfortunately, there were a lot of spam entries to clean up, but Gary worked on this as time allowed.

A couple of weeks ago, Gary started having more problems with his guestbook. It was slow and, more importantly, it wasn’t taking new posts. After some digging around, I found out that it was slow because PYG stored all the entries in a simple text file. THis is OK (and maybe ideal) for a guestbook with a few posts. Gary’s guestbook is active and covers several years. Also, there were still a fair number of spam posts that were not visible (Gary’s guestbook is moderated), but still in the text file. Altogether, Gary has over 3000 posts in his guestbook. The combination of simple text file storage with some inefficient coding in PYG and 3000+ posts was resulting in slow page generation. Gary allows HTML in posts. This is mostly so that this guests can post links to pictures, other concerts and videos (on Youtube, etc.). Allowing HTML can cause problems, but, because his guestbook is moderated, the problems should be correctable. Unfortunately, posts with invalid HTML tripped up the PYG administration interface. So, I started looking for a new guestbook script. PYG doesn’t have a version that supports MySQL. I wanted something that:

  • Used PHP 4.x
  • Used MySQL
  • Used templates to create the Guestbook pages
  • Allowed the guestbook to be moderated

Oddly enough, I couldn’t find anything that met these objectives. I searched Google and SourceForge. I came across tons of Guestbook projects. Some required PHP 5. Others didn’t use templates. I found one that used PHP 4 and templates but didn’t support moderation. So, I ended up writing one from scratch. I’ve already got one PHP project on SourceForge, phpHitCounter. phpGuestbook is already taken, so I’m thinking phpMysqlGuestbook will be the name. Here are the highlights:

  • Simple configuration (config.php) and installation (edit config.php and run .sql script to create database).
  • Excellent error messages and error handing for end users ((JavaScript and in page error reporting).
  • Extra feedback for end users via a special page that explains post moderation.
  • Fast post display for both end users and administrators
  • Emails sent to the moderator include a link to the post to be reviewed
  • Simplified administration
  • Simple template based customization of HTML output. Templates are valid HTML so they can be maintained in FrontPage, Dreamweaver, etc.
  • Option to allow HTML content in end user posts. Careful handling of user supplied HTML content in administration interface.
  • Comprehensive support for banned IPs and banned/moderated content

This script is a nice companion to phpHitCounter.

Leave a Reply

Powered by Teztech