Commentator is an extremely simple PHP comments system that uses a MySQL database.
Requires PHP 5+ and a MySQL database. I think even the really old versions of MySQL should work.
» commentator.zip (8KB) - changelog
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>
require_once argument needs to point to the Commentator PHP file (I renamed it to "comments.php"). You only need it once, as the above code should be the only thing that varies from page to page where you want comments.Commentator() should be a name unique to the page, as it is what the MySQL table will be called.new Commentator bit.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).
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>';
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!
BSD-style license. This means you can pretty much do whatever you want as long as you give due credit.
If the steps above didn't help, if you encounter bugs or if you have any other questions, email me:
r [at] this domain
Thank you very much for scripts.
#1 – 7 January, 2010 at 4:54 pm
thank you very much for the script
#2 – 22 January, 2010 at 12:57 pm
Thanks, this is a great script.
If you are going to update it, will you please consider adding "reply" to comments (like threaded comments in wordpress)? That would make this script the best!
#3 – 25 January, 2010 at 4:07 am
That's a good idea, Sven. I'll add it in the next update.
No promises when that'll be, but I'll post a comment here when I do, so if you're subscribed to comments here you'll know.
#4 – 4 February, 2010 at 11:10 am
Thanks again Rafael, that would be great!
I am already looking forward to it ;)
PS: I subscribe to follow-up comments , sould you add a comment here when the script is updated?
#5 – 7 February, 2010 at 6:08 am
Some changes made:
- Total no. of comments can be shown
- Comments by page owner are highlighted (like this one)
- Comments can be unmarked as spam and all spam just deleted in one go
See documentation above for details.
Sven: no threads yet, it's pretty complicated actually. For example, should it be allowed for comments to be nested unlimitedly, or for people to be allowed to reply only to a non-reply comment? What happens when there are hundreds or thousands of comments? Pagination would be needed.
I'm going to think more about this and then hopefully do something about it.
#6 – 21 February, 2010 at 11:37 am
Thanks for updates and additions Rafael , they are great!
It might be complicated to do threaded/nested comments, but I would suggest to have a look at the add-ons to Wordpress (the ones that were made before it was "built in" as standard).
A few reply to would normally be enough, like setting max thread depth 5 (?)
I do not think that there should be any limit in number of replies, but is should be noticeable that it is a reply to another comment.
It is somehow "obligatory" in a modern online communication to have a good and clear system for visitors to read/write comments.
Pagination could be needed for very popular pages. Text don not take to long to download, so for me a long page would be preferred over pagination (others might prefer limited comments per page).
But it is all up to you, your comment system is already very easy to use and simple to install so nested comment/pagination would just be extra "bonuses".
Thanks again Rafael :)
#7 – 21 February, 2010 at 4:05 pm
Hello I am looking for a VERY simple way for people to comment on stories contained in a website I am working on so I am trying this out !
#8 – 26 February, 2010 at 10:08 pm
@ John
A good choice, it is a good script!
#9 – 27 February, 2010 at 10:10 am
Bonjour
C'est vraiment un bon script de commentaires
#10 – 6 March, 2010 at 10:45 pm
this script looks great; can't wait to try it out!
#11 – 2 April, 2010 at 10:55 am
nice script
look forward to updates if you have the time
#12 – 30 April, 2010 at 6:42 pm
This looks like a really cool script but i'm getting this message with these errors:
Success... Localhost via UNIX socket
No MySQL connection set up!
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/mysites/public_html/cmscommerce/restart/includes/modules/comments.php on line 207
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in /home/mysites/public_html/cmscommerce/restart/includes/modules/comments.php on line 208
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /home/mysites/public_html/cmscommerce/restart/includes/modules/comments.php on line 209
#13 – 20 May, 2010 at 6:24 am
It looks like you haven't set up the MySQL connection properly. You have to provide a function called "mysql_connection" that can be called by the script (see line 31). Like it says at the top of the script, there is a sample one you can use at the bottom:
/* // Mysql connection function, in case it isn't provided elsewhere already // You have to replace the parameters in msqli_connect and in mysqli_select_db with your own function mysql_connection() { $link = mysqli_connect('mysql.example.com', 'username', 'password'); if (!$link) return false; if (!mysqli_set_charset($link, 'utf8')) return false; if (!mysqli_select_db($link, 'database_name')) { echo 'db selection error:' . mysqli_error($link); return false; } return $link; } */Remove the comments and put the right parameters in.
#14 – 20 May, 2010 at 11:35 am
thanks
#15 – 29 May, 2010 at 6:43 pm
I hate Lindsay Lohan.
Chelsea Handler rocks.
The moon is an artificial small planet made by aliens.
#16 – 20 June, 2010 at 9:14 pm
Hi, I installed it on localhot (wampserver) but I´m getting all sorts of errors (Undefined property/variable/index).
Commenting is actually working but the errors are all over the comments and comment box.
#17 – 5 July, 2010 at 5:54 am
Bruno:
I can't really help without knowing exactly what the errors are. Can you paste the entire errors here?
Also let me know if you've made any modifications to the script (except for putting in your correct MySQL information).
#18 – 11 July, 2010 at 4:47 am
I´ve set akisment, e-mail, gravatars to false and set the mysql connection at the bottom.
Here are the errors http://pastebin.com/JLyXqSAm
#19 – 11 July, 2010 at 8:58 am
Ah, that's because your server must have a very strict error reporting setting by default.
Put this at the top of the PHP script:
error_reporting(E_ALL ^ E_NOTICE);#20 – 11 July, 2010 at 10:24 am
Thanks, it works. Do I have to care about the errors or are they "normal"?
#21 – 11 July, 2010 at 2:56 pm
They're "normal". They are there to help developers debug code and should not be turned on for code that's released into the wild.
#22 – 11 July, 2010 at 3:19 pm
Ok, there´s another thing. It seems under certain conditions the system sends mail notifications multiple times. It occured in my localhost and also with your last reply.
When I refresh the page just after I´ve posted the comment gets duplicated.
#23 – 12 July, 2010 at 2:32 am
I think it is an oversight I found a while back, as I was also getting double emails. I updated the code but forgot to re-upload it.
Download the zip again, update your PHP file and you should be OK. Don't forget to preserve your settings.
#24 – 12 July, 2010 at 11:36 am
Ok, but there´s still a minor bug with duplicate post when I refresh the page just after I´ve commented (when the #comments section is displayed).
#25 – 17 July, 2010 at 12:59 pm
thank you very much for the script
#26 – 26 July, 2010 at 2:33 pm