1

嗨,我正在运行一个 mysql 插入查询,这个想法是用户可以向用户个人资料提交评论,但我想知道是否有一种方法可以阻止令人反感的词语、链接并防止人们使用博客链接等向其发送垃圾邮件。

我会使用 php if 语句来说明忽略这些关键字吗?“f*ck”等,我觉得这样的唯一问题是我必须在忽略语句中包含每个单词,

或者我会在我的mysql中包含一些东西,无论哪种方式我都想阻止所有链接插入到表单中,

有人可以给我一些指导并告诉我我将如何做到这一点,谢谢

html:

<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<textarea name="review_recipient" id="review_recipient" maxlength="180" cols="33" rows="5" style=""></textarea><label style="">Who is the Review from?</label>
<br/>
<textarea name="review_content" id="review_content" maxlength="180" cols="33" rows="5" style=""></textarea>
<label style="">Say Something...</label>

<input name="add_review" type="image" src="http://www.playtimeboys.com/assets/img/icons/save-edit.png" BORDER="0" ALT="SUBMIT!"class="review_submit4" /></form> 

php/mysql:

<?php ob_start(); ?>
     <?php 
    // check if the review form has been sent
    if(isset($_POST['review_content']))
    {
        $content = $_POST['review_content'];
            //We remove slashes depending on the configuration
            if(get_magic_quotes_gpc())
            {
                    $content = stripslashes($content);
            }
            //We check if all the fields are filled
            if($_POST['review_content']!='')
            {


                {
                $sql = "INSERT INTO ptb_reviews (id, from_user_id, to_user_id, content) VALUES (NULL, '".$_SESSION['user_id']."', '".$profile_id."', '".$content."');";
                mysql_query($sql, $connection);

                $_SESSION['message']="<div class=\"infobox-wallpost\"><strong>Thank You</strong> - Your review has been sent and is awaiting approval.</div><div class=\"infobox-close4\"></div>"; 
    header("Location: {$_SERVER['HTTP_REFERER']}");

    } } } } ?>
4

2 回答 2

1
$blocked_words="test1,test2,test3,test4";//list of offensive word
$review_from_user ="Your reviews test2 is following hello test1"; //review from user 


$blocked_words_expo = explode(",", $blocked_words);  

foreach($blocked_words_expo as $rmv)
{
    if(strpos($review_from_user,$rmv)==true)
    {
        $review_from_user = str_replace($rmv,'',$review_from_user); 
    }
}
echo $review_from_user;

//and then insert $review_from_user
于 2013-05-01T13:17:34.643 回答
0

您可以尝试从坏词表中获取值。如下所示

$blocked_words=array();
$q="select words from block";
$rs=mysql_query($q);
while($rd=mysql_fetch_object($rs))
{
$blocked_words[]=$rd->words;
}
$string_words=explode(" ", $_POST['review_content']);  
$result = array_intersect($blocked_words, $string_words);  

通过上面的代码,您将把表“块”中的所有单词放入 $blocked_words。您可能需要根据您的需要进行更改

于 2013-05-01T10:46:23.477 回答