Skrypt, filtruje słowa ale czy jest możliwość go nieco zmodyfikowania po to ze jak wykryje jakieś niewłaściwe słowo, komentarz w ogóle nie zostanie dodany i będzie widnieć napis że: “użyto niewłaściwe wyrazy (czy coś w tym stylu)” i wysłania wiadomość w ogóle się nie pojawi…
Modyfikowany skrypt:
<?php
function censor($content){
$words_list=@file('swearwords.txt');
$search=array('a','b','i','l','o','p','s');
$replace=array('(?:a|\@|\*)','(?:b|8|3|\*)','(?:i|1|l|\!|\*)','(?:l|1|i|\!|\*)','(?:o|0|\*)','(?:p|\?|\*)','(?:s|\$|\*)');
foreach($words_list as $badword){
$badword=rtrim($badword);
$len=strlen($badword);
if($len <= 0) continue;
$rep='';
for($i=0; $i < $len; $i++) break; {
$rep.='-';
}
// Check to see if this word has brackets around it. If it is bracked, censor it in a simple form.
if (substr($badword, 0, 1) == "[" && substr($badword, ($len - 1), 1) == "]") {
$content = preg_replace("@".substr($badword, 1, ($len - 2))."@i", substr($rep, 0, (strlen($rep) - 2)), $content);
continue;
}
$badwordpreg=preg_split('//', $badword, -1, PREG_SPLIT_NO_EMPTY);
$badwordpreg=str_replace($search, $replace, $badwordpreg);
$badword='';
for($i=0; $i < count($badwordpreg); $i++){
$badword.=$badwordpreg[$i];
if($i != (count($badwordpreg)-1)) $badword.='(.{0,5})';
}
$badword="/$badword/i";
$content=preg_replace($badword, $rep, $content);
}
return $content;
}
$name = htmlspecialchars($_GET['flot1']);
$message = htmlspecialchars($_GET['flot2']);
if ($message != '')
{
$name = censor($name);
$message = censor($message);
$message = str_replace ("\n","
",$message);
$message = strip_tags ($message, '
');
$newRow = '
’. strip_tags ($name) . '’ . date(‘d.m.Y H:i’) . ‘’ . ($message) . ’
‘; $oldRows = join (’’, file (‘shoutbox_wpisy.txt’) ); $fileName = fopen (‘shoutbox_wpisy.txt’, ‘w’); fputs ($fileName, $newRow . chr(13) . chr(10) . $oldRows); fclose ($fileName); } header(“Location: main.php?dzial=1#KOMENTUJ”); ?> [/code]
Dziękuję za pomoc…