PHP Fusion Mod: Anonymous Guest Comments
I wanted to allow people to leave comments on my PHP Fusion site without the hassle of registration or logging in. That process has always annoyed me about sites, when all I have wanted to do was say thanks or something, and not be forced to jump through hoops to do so.
When attempting to implement a quick and easy system, I was confronted with two main issues:
- Php Fusion doesn’t allow a method via the back end administration to allow commenting by guest users.
- Open commenting is asking for trouble from spammers who bombard your site with porn links, etc.
(UPDATE TO WHAT FOLLOWS: note that I still have received spam. If a person whats to post it, there’s nothing you can do, except disable comments altogether. If a bot it still getting through, then the Botslap infusion might be a solution.)
The first issue is solved by some simple edits to the /includes/comments_include.php file. I found out how to do this on a forum site. You simply need to find 3 references to
$settings['guestposts'] == “1″ and change the 1 to a 0.
What this does is allow commenting by anyone.
So near the beginning find
if ((iMEMBER || $settings['guestposts'] == “1″) && isset($_POST['post_comment'])) {
Change the “1″ to a “0″
Then find
} elseif ($settings['guestposts'] == “1″) {
Change the “1″ to a “0″
Lastly, find
if (iMEMBER || $settings['guestposts'] == “1″) {
Change the “1″ to a “0″
Next I downloaded the Comments Spam Protection mod from here
It’s simply a comments_include.php replacement. I noticed that this was for an earlier version than my PHP Fusion, and that its code was quite different from my existing comments_include.php. It seemed to work, but I decided not to risk using it and instead transferred the necessary code across to my existing comments_include.php.
I prefered my spam protection math question to be at the top rather than the bottom, so it wasn’t quite and direct transfer. Also, because of code differences, I had to add a little bit of code of my own.
First find
}
redirect($clink);
}
and change it to this (here is where you can put your own error message)
} else {
$invalid = true;
$comment_message2 = trim(stripinput(censorwords($_POST['comment_message'])));
echo “<div style=’text-align:center’><br />You must answer the maths question correctly for your comment to be added. This is to prevent bots from spamming the comments. We apologise for the inconvenience.<br /><br /></div>”;
}
if(!$invalid) redirect($clink);
}
Next find (note it’s c102, not c100)
tablebreak();
opentable($locale['c102']);
and insert the numbers generation code like this
tablebreak();
// Calculate random equation and answer
$var1 = rand(1,5);
$var2 = rand(1,5);
$equation = $var1 . ” + ” . $var2 . ” = “;
$validation_answer = $var1 + $var2;opentable($locale['c102']);
Lastly, find this
echo “<tr>
<td align=’center’><textarea name=’comment_message’ rows=’6′ class=’textbox’ style=’width:400px’></textarea><br>
and insert the code for the input field like this
echo”<tr style=’ text-align: left; height: 25px;’>
<td>”.$equation.” <input type=’text’ name=’validation’ value=” class=’textbox’ style=’width:250px’>
<input type=’hidden’ name=’validation_answer’ value=’$validation_answer’ class=’textbox’ style=’width:250px’>
</td>
</tr>
<tr>
<td align=’center’><textarea name=’comment_message’ rows=’6′ class=’textbox’ style=’width:400px’>”;
if($invalid) echo $comment_message2; echo”</textarea><br>
That’s it. You’re good to go.

