Permalink
Browse files

Add anti-spam explicit field

Require the user to answer a very simple question to limit spam.
  • Loading branch information...
rom1v committed Feb 16, 2017
1 parent 042e49c commit c791f464bbfdd9e361d1e9137fbea7cab847d481
Showing with 10 additions and 9 deletions.
  1. +7 −7 _includes/comments.html
  2. +3 −2 comments/submit.php
View
@@ -25,10 +25,9 @@ <h2 id="comments">Commentaires</h2>
<p><em>Les commentaires sont fermés.<em></p>
{% else if %}
<h3 class="comment-title">Poster un commentaire</h3>
-<form method="POST" action="/comments/submit.php" onSubmit="noSpam()">
+<form method="POST" action="/comments/submit.php">
<input type="hidden" name="post_id" value="{{ page.id }}" />
<input type="hidden" name="return_url" value="{{ page.url }}" />
- <input type="hidden" id="antispam" name="antispam" value="" />
<table class="comment-table">
<tr>
<th>Nom :</th>
@@ -51,6 +50,12 @@ <h3 class="comment-title">Poster un commentaire</h3>
<em>(optionnel)</em>
</td>
</tr>
+ <tr>
+ <td colspan="2">
+ Quelle est la 3e lettre du mot <code>blog</code>&nbsp;? <input type="text" name="antispam" size="1" maxlength="1" />
+ <em>(antispam)</em>
+ </td>
+ </tr>
<tr>
<td colspan="2">
<textarea name="comment" rows="10"></textarea><br />
@@ -64,11 +69,6 @@ <h3 class="comment-title">Poster un commentaire</h3>
</tr>
</table>
</form>
-<script type="text/javascript">
-function noSpam() {
- document.getElementById('antispam').value = "not-a-stupid-robot";
-}
-</script>
{% endif %}
{% endif %}
{% endif %}
View
@@ -42,8 +42,9 @@
* HERE BE CODE
****************************************************************************/
-if (!isset($_POST["post_id"]) || $_POST["antispam"] !== "not-a-stupid-robot") {
- http_response_code(403);
+if (!isset($_POST["post_id"]) || $_POST["antispam"] !== "o") {
+// do not indicate to bots that this is an error
+// http_response_code(403);
header('Content-Type: text/plain; charset=utf-8');
echo "Soumission refusée.";
return;

0 comments on commit c791f46

Please sign in to comment.