Add very basic spam filter to guestbook
This commit is contained in:
parent
6a8da5f22a
commit
21c1fa2b7c
1 changed files with 44 additions and 25 deletions
|
@ -17,8 +17,22 @@
|
|||
<div id="pagebody">
|
||||
<div id="content">
|
||||
<?php
|
||||
$banned_keywords = array("financial", "finance", "stymn", "world4news", "invest");
|
||||
$contains_keywords = array();
|
||||
$name = strip_tags($_POST["name"]);
|
||||
$msg = strip_tags($_POST["message"]);
|
||||
$prohibit = false;
|
||||
foreach ($banned_keywords as $keyword) {
|
||||
if (strpos(strtolower($msg), $keyword) !== false) {
|
||||
$prohibit = true;
|
||||
array_push($contains_keywords, $keyword);
|
||||
}
|
||||
if (strpos(strtolower($name), $keyword) !== false) {
|
||||
$prohibit = true;
|
||||
array_push($contains_keywords, $keyword);
|
||||
}
|
||||
}
|
||||
if (!$prohibit) {
|
||||
if ($msg === "" || $name === "" || strip_tags(htmlspecialchars_decode($msg)) === "") {
|
||||
echo '<b>You must provide both a name and message!</b>';
|
||||
} else {
|
||||
|
@ -44,7 +58,12 @@
|
|||
$stmt->execute();
|
||||
echo '<b>Success!</b>';
|
||||
}
|
||||
?><br><br>
|
||||
} else {
|
||||
echo '<b>Your message could not be submitted as it (or your username) contains the following prohibited keywords:</b><br>'.PHP_EOL;
|
||||
echo ' <pre>'.join(', ', $contains_keywords).'</pre>'.PHP_EOL;
|
||||
}
|
||||
?>
|
||||
<br><br>
|
||||
<a href="./">Back</a>
|
||||
</div> <!-- content -->
|
||||
|
||||
|
|
Loading…
Reference in a new issue