2016-03-27 15 views
-1

Web sitemde bir sohbet yapıyorum, ancak hesapları yok, bu yüzden küfür yayıyor. Tüm verilerimi user.txt'a yazmak için PHP kullanıyorum. Php akılsız küfür için basit bir filtre var mı? Kullandığım bu js çok iyi iş gibi görünmüyor Çünkü: Burada PHP sohbet sansürü

$(function() { 
 
    $("input:submit[name='submit']").on("click",function() { 
 
    var name = $("input:text[name='name']").val(); 
 
    var message = $("input:text[name='field2']").val(); 
 
    var badwords = ["dingbat", "poopy"]; 
 

 
    /* do this */ 
 

 
    if($.inArray(name, badwords) !==-1 || $.inArray(message, badwords) !==-1) { 
 
     alert("Your Message Contains Bad Words, Please Remove Them Before Proceeding"); 
 
     return false; 
 
    } 
 
    }); 
 
});
(sadece user.txt görüntüler eksi txt.php) benim tam kod

@import url(https://fonts.googleapis.com/css?family=Lato:400,100,300); 
 
#blu { 
 
background: #F0FAFF; 
 
padding: 3; 
 
width: 310; 
 
     } 
 
\t \t b, i, p { 
 
-webkit-transition: all 0.5s ease; 
 
    font-size: 16px; 
 
    font-size: 1rem; 
 
    line-height: 23px; 
 
    line-height: 1.4375rem; 
 
    font-weight: 400; 
 
    font-style: normal; 
 
    font-family:"Lato"; 
 
} 
 
iframe{border: 3px solid white;} 
 

 
button,input, #rcp_submit, #rcp_update_card { 
 
    display: inline-block; 
 
    font-family: "Lato", sans-serif; 
 
    font-weight: 500; 
 
    outline: 0; 
 
    border-radius: 0; 
 
    color: black; 
 
    background: #FFFFFF; 
 
    white-space: nowrap; 
 
    padding: 9px 16px !important; 
 
    line-height: 1.4; 
 
    border: 0; 
 
\t color:black; 
 
    position: relative; 
 
    -webkit-transition: 0.1s; 
 
    transition: 0.1s; 
 
}
,!--this file is called c5.php--> 
 
<?php 
 
if(isset($_POST['field1']) && isset($_POST['field2'])) { 
 
    $data = $_POST['field1'] . '-' . $_POST['field2'] . "<br>"; 
 
    $ret = file_put_contents('user.txt', $data, FILE_APPEND | LOCK_EX); 
 
    if($ret === false) { 
 
     die('There was an error writing this file'); 
 
    } 
 
    else { 
 
\t echo "$ret bytes written to file<a href ='javascript:history.go(-1)'>go back</a>"; 
 
    } 
 
} 
 
else { 
 
    die('no post data to process'); 
 
} 
 
?> 
 
<html> 
 
<body onload="reloadIFrame();"> 
 
<script> 
 
window.setInterval("reloadIFrame();", 3000); 
 
function reloadIFrame() { 
 
document.getElementById("myIframe").src="txt.php"; 
 
} 
 
</script> 
 
<div id ="blu"> 
 
<table> 
 
<p>Chat about your code</p> 
 
<td> 
 
<iframe src ="txt.php" id ="myIframe"></iframe><br/> 
 
<button onclick="reloadIFrame();">Refresh feed</button> 
 
<form action="c5.php" method="POST"> 
 
<p>Name:</p> 
 
    <input name="field1" type="text" /> 
 
\t <h3>&nbsp;</h3> 
 
<p>Question:<p> 
 
    <input name="field2" type="text" /> 
 
    <input type="submit" name="submit" value="Submit"> 
 
</form> 
 
<a href="user.txt" download="chatlogs">download chat logs</a> 
 
</td> 
 
</table> 
 
</div>

olduğunu
+5

hiç çalışmaz, insanlar her zaman yaratıcı yollar bulacaksınız c_u_r_s_e –

+0

Böyle bir JS tabanlı filtre, filtrelemek istediğiniz geçerli ve eksiksiz bir kelime kataloğuna sahip olduğunuz varsayılarak, mükemmel şekilde çalışmalıdır. Peki sorun nedir? Gerçekte ne demek "çok iyi çalışmıyor gibi görünüyor"? – arkascha

+0

Ve genel bir soru: Sitenizi ziyaret ettiklerinde insanların küfür ettikleri bu kadar sinirlenmiş gibi görünüyor? Bu internette yaygın değil ... – arkascha

cevap

0

hadi bir bakalım t js neden çalışmıyor

Bütün bir kelime bir cümleye eş. var nameBADWORD SOMEONE_BADWORD ise burada dizi (BADWORD SOMEONE_BADWORD)

yani ne yapmanız gerektiğini temel bileşenini var kelime

name.split(/[(\s|_)]/) // split the name by white space or underscore 
içine cümleyi ayrılmıştır bu değeri tutan eğer ne aradığını bir örnektir

şimdi

["BADWORD", "SOMEONE", "BADWORD"]

dizisi olacak

ve kod olur:

$(function() { 
    function containBadWord(words , banlist){ 
    var bad = false; 
    $.each(words , function(k , v){ 
     if($.inArray(v, banlist) !==-1){ 
      bad = true; 
      return false; 
     } 
    }); 
    return bad; 
    } 
    $("input:submit[name='submit']").on("click",function() { 
    var name = $("input:text[name='']").val(); 
    var name_split = name.split(/[(\s|_)]/); 
    var message = $("input:text[name='field2']").val(); 
    var message_split = message .split(/[(\s|_)]/); 
    var badwords = ["dingbat", "poopy"]; 

    /* do this */ 
    if(containBadWord(name_split , badwords)){ 
    alert("your name has bad words") 
    } 

    if(containBadWord(message_split , badwords)){ 
    alert("your messagehas bad words") 
    } 
    }); 
}); 

düzenleme: sizin jquery seçiciler tüm yanlış yanı, çünkü Yukarıdaki kod çalışma değildi

. Burada

`input:text[name='']` will select an input with an empty attribute of `name` 

https://jsfiddle.net/tq7odeLg/

+0

dosen't çalışma ... – 500man

+0

Daha fazla iş için yorum yapma umarım, ama ne işe yaramazsa soruyorum! Bunu test ettim ve –

+0

@ 500man için js fiddle'a bakın ve –

0

Bu çalıştı kodunun çalıştığını ve işe yaradı:

<?php 
 

 
$find=array('bad','word','words'); 
 

 
$replace=array('...','...','...'); 
 

 
if(isset($_POST['user_input'])&&!empty($_POST['user_input'])) 
 
\t  $data = $_POST['name'] . '-' . $_POST['user_input'] . "<br>"; 
 
$ret = file_put_contents('user.txt', $data, FILE_APPEND | LOCK_EX); 
 
    if($ret === false) { 
 
     die('There was an error writing this file'); 
 
    } 
 
    else { 
 
    } 
 
{ 
 

 
$user_input=$_POST['user_input']; 
 

 
$user_input_new=str_ireplace($find,$replace,$user_input); 
 

 
} 
 
?> 
 

 
<p> <?php 
 
     $text = file_get_contents('user.txt'); 
 
     echo $text; 
 
    ?> 
 
</p> 
 
<style> 
 
@import url(https://fonts.googleapis.com/css?family=Lato:400,100,300); 
 
b, i, p { 
 
-webkit-transition: all 0.5s ease; 
 
    font-size: 16px; 
 
    font-size: 1rem; 
 
    line-height: 23px; 
 
    line-height: 1.4375rem; 
 
    font-weight: 400; 
 
    font-style: normal; 
 
    font-family:"lato"; 
 
} 
 
</style> 
 

 
<hr> 
 

 
<form action="ws.php" method="POST"> 
 
<p>name:</p><input name ="name" type ="text"></input><br/> 
 
<p>comment:</p><br/><textarea name="user_input" rows="6" col="30"> 
 
</textarea><br/> 
 
<input type="Submit" value="Submit"> 
 

 
</form> 
 
</form>

İlgili konular