siwwy :3 #3
					 1 changed files with 44 additions and 25 deletions
				
			
		Add very basic spam filter to guestbook
				commit
				
					
					
						21c1fa2b7c
					
				
			
		| 
						 | 
					@ -17,8 +17,22 @@
 | 
				
			||||||
<div id="pagebody">
 | 
					<div id="pagebody">
 | 
				
			||||||
	<div id="content">
 | 
						<div id="content">
 | 
				
			||||||
		<?php
 | 
							<?php
 | 
				
			||||||
 | 
							$banned_keywords = array("financial", "finance", "stymn", "world4news", "invest");
 | 
				
			||||||
 | 
							$contains_keywords = array();
 | 
				
			||||||
		$name = strip_tags($_POST["name"]);
 | 
							$name = strip_tags($_POST["name"]);
 | 
				
			||||||
		$msg = strip_tags($_POST["message"]);
 | 
							$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)) === "") {
 | 
								if ($msg === "" || $name === "" || strip_tags(htmlspecialchars_decode($msg)) === "") {
 | 
				
			||||||
			    echo '<b>You must provide both a name and message!</b>';
 | 
								    echo '<b>You must provide both a name and message!</b>';
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
| 
						 | 
					@ -44,7 +58,12 @@
 | 
				
			||||||
			    $stmt->execute();
 | 
								    $stmt->execute();
 | 
				
			||||||
				echo '<b>Success!</b>';
 | 
									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>
 | 
							<a href="./">Back</a>
 | 
				
			||||||
	</div> <!-- content -->
 | 
						</div> <!-- content -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue