Commentator: a really simple PHP comments system

Commentator is an extremely simple PHP comments system that uses a MySQL database.

Features

Download

Requires PHP 5+ and a MySQL database. I think even the really old versions of MySQL should work.

» commentator.zip (8KB) - changelog

Usage

You need to put some PHP into your own code where you want the comments (and the comment form) to appear. For example, this page contains all comments in a DIV, with an H2 element as a heading, which includes the total number of comments.

<?php
  require_once('../comments.php');
  $comments = new Commentator('commentator', 'Commentator: a really simple PHP comments system');
?>
  <h2 id="comments">Comments (<?php echo $comments->commentcount; ?>)</h2>
  <div class="section">
<?php $comments->write() ?>
  </div>

Spam protection

The script optionally employs the Akismet PHP5 class to avoid spam comments. I really recommend it, as it works really well and spam is pretty ubiquitous. As an example, within two days of putting this page up, there were already comments about viagra being submitted (but they got caught).

To use it you will need a WordPress API key. It is very easy to get and does not mean you need to get any other WordPress stuff - they'll give it to you for free, which is very nice of them.

When you download the Akismet PHP class, you only need the main PHP file (Akismet.class.php).

Settings

You will need to set some variables at the top of commentator.php. None of these are absolutely critical for the operation of the script, but they are important nevertheless. They are quite self-explanatory:


$akismet_file = 'Akismet.class.php';               // Akismet PHP5 class file
$wpAPIkey = 'xxxxxxxxxxx';                         // WordPress API key
$commentator_from = 'noreply@example.com';         // email address to appear in "From" field
$email_owner = 'me@example.com';                   // new non-spam comments posted are sent to this address. Set to false to disable
$commentator_password = 'password';                // Password to enable you to delete comments
$gravatars = true;                                 // Use of gravatars. Set to false to disable them

// Allowed HTML tags in comments. Set to '' to disable HTML altogether
$html_comments = '<a><i><b><em><u><s><strong><code><pre><p>';

Deleting comments

As you can see in the settings section above, you can set a password. This will make a checkbox appear next to each comment, and these buttons at the bottom:

To use this feature, you must add ?password=xxxx to the end of the URI. To make spam comments visible, also add &show=all to the query string. So to be able to delete spam and non-spam comments from a page at http://example.com/blog/, you would need to type in http://example.com/blog/?password=xxxx&show=all.

The buttons are pretty self-explanatory. The number in the last button just tells you how many comments are spam. It appears regardless of whether spam comments are showing or not, so use with caution!

License

BSD-style license. This means you can pretty much do whatever you want as long as you give due credit.

Contact

If the steps above didn't help, if you encounter bugs or if you have any other questions, email me:

r [at] this domain

Comments (26)

Post a comment (Optional)
  • Allowed markup: <a> <i> <b> <em> <u> <s> <strong> <code> <pre> <p>
  • All other tags will be stripped, unless they are in a <pre> (use this for blocks of code)
  • External links will have the rel="nofollow" attribute applied