need help with bad word filter
Posted: Sat Dec 02, 2006 4:21 pm
hi all. Im trying to implement a bad words filter to my guest book but im having prolems with it can someone help me try and sort it out please.
I think my problem is when i am accessing the text field to get my comments out to check. This is my code below which i have so far.
Jon
I think my problem is when i am accessing the text field to get my comments out to check. This is my code below which i have so far.
Code: Select all
<?php
$file = "gb.txt";
$open = fopen($file, "r")
or die("txt file missing");
$size = filesize($file);
$fstring = fread($open,filesize($file)+1);
?>
<script language=javascript>
//checks to see if the domains are valid and @ sign is present
function emailCheck(emailAddress){
var domain = new Array('.com','.net','.ac','.co','.uk');
var eAdd = emailAddress;
var val = true;
var indexOfDot = eAdd.lastIndexOf(".");
var ext = eAdd.substring(indexOfDot,eAdd.length);
var atSignIndex = eAdd.indexOf("@");
if(indexOfDot > 5 && atSignIndex >1){
for(var i=0; i<domain.length; i++){
if(ext == domain[i]){
val = true;
break;
}else{
val = false;
}
}
if(val == false){
alert("Your Email Address "+eAdd+" is not correct");
return false;
}
}else{
alert("Your Email Address "+eAdd+" is not correct");
return false;
}
return true;
}
</script>
<?
$comment = (commentForm.comment.value);
function BadWordFilter(&$comment, $replace)
{
$bads = array (
array("<span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span>","f***"),
array("wank","w***"),
array("<span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span>","s***")
);
if($replace==1) {
$remember = $comment;
for($i=0;$i<sizeof($bads);$i++) {
$comment = eregi_replace($bads[$i][0],$bads[$i][1],$comment);
}
if($remember!=$comment) return 1;
} else {
for($i=0;$i<sizeof($bads);$i++) {
if(eregi($bads[$i][0],$comment)) return 1;
}
}
}
$any = BadWordFilter($wordsToFilter,1);
$any = BadWordFilter($wordsToFilter,0);
?>
<form name=commentForm action="added.php" METHOD="POST" onSubmit="return BadWordFrilter(commentForm.comment.value)" onSubmit="return emailCheck(commentForm.from.value)">
Name *:
<input type="text" name="name" size=20 maxlength="20">
<br>
<p><br>
Email *:
<input type="text" name="from" size=27 maxlength="50" >
</p>
<p> </p>
WebSite:
<input type="text" name="webs" size=27 maxlength="50"></td>
<div align="left"><br>
Please add your comments<br>
<textarea name="comment" rows=11 cols=55 wrap=physical></textarea>
<br>
</div><div align="left">
<input type="submit" value=" Add " >
</div>
</form>