Forum Moderators: coopster
if (strpos($value, "essay")) {
$er=$er+1;
echo "<center><font size='-1' color='red'>Your name is noted as spammy.</font></center><br>";}
$badwords = array {
'bad1',
'bad phrase',
'another bad phrase'
};
//
if (check_input($_POST['comments'],$badwords)) {
echo '<p style="margin:auto; color:red">Your comment is noted as spammy.</p>";
exit;
}
//
function check_input($input,$list) {
$spam=null;
foreach ($list as $phrase) {
if (strpos($input, $phrase)===true) { // Note THREE
$spam=1;
break;
}
}
return $spam;
}
if (preg_match("/$phrase/i",$input)) {
$spam=1;
break;
}
$spammywords=array('forum','dissertation');
//
if (check_input($_POST['comments'],$spammywords)) {
echo '<p style="margin:auto; color:red">Your comment is noted as spammy.</p>';
$er=$er+1;
}
//
function check_input($input,$list) {
$spam=null;
foreach ($list as $phrase) {
if (stripos($input, $phrase)===true) { // Note THREE
$spam=1;
break;
}
}
return $spam;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled</title>
</head>
<body>
<?php
if ($_POST) {
$badwords = array (
'bad1',
'bad phrase',
'another bad phrase'
);
$errors=null;
//
foreach ($_POST as $key=>$value) {
if (check_input($value,$badwords)) {
$errors .= "<li style=\"list-style:none; color:red\">Spam detected in the $key field.</li>\n";
}
}
} // End if POST
// Function - must reside OUTSIDE logic blocks
function check_input($input,$list) {
$spam=null;
foreach ($list as $phrase) {
// if (stripos($input, $phrase)===true) { // Note THREE
if (preg_match("/$phrase/i",$input)) {
$spam=1;
break;
}
}
return $spam;
} // end function
?>
<form method="post" action="input-test.php">
<?php if ($errors) { echo "<ul>$errors</ul>"; }?>
<p><label for="yourname">Your Name</label>:
<input type="text" name="yourname" id="yourname" value="bad1"></p>
<p><label for="comments">Comments</label>:
<textarea name="comments" id="comments" rows="3" cols="20">bad phrase</textarea></p>
<p><input type="submit" value="Test Me"></p>
</form>
</body>
</html>