Add or Follow me

[PHP] Protecting pages of comment spammers. (Simple)



HOW if there are people who write comments fraudulent junk (spam) on the web page that allows users to write comments, for example in the guest book, comment on articles, etc.? It is indeed rather difficult, considering that if someone wrote a long comment, not necessarily it is spam, and not necessarily that a comment that according to website content. So here are some ways to minimize it.
1. Changing the words that are not polite.not uncommon in a person's comment contains words that smells sara, porno, curses, etc, this is quite annoying if there are other visitors who read the comments, for that we need to check every word written by the user before we show on website. PHP function that we can use here is the function str_replace (), but previously we also need to create a list of words that are forbidden words.


[Code]
<? Php
$
list_of_forbidden_words  = array ("ugly", "smell", "crooked", "etc");$ Comment = str_replace ($ list_of_forbidden_words ,"***",$ comments);
echo $ comment;
?>
[/ Code]


so that with these functions, so any comments that contain the words in the variable $ daftar_kata_terlarang will be changed to ***.
2. Changing the display format becomes Wrapping comment.Usually there is a spam that contains words that are very long, and can result in the table on page commentary becomes too wide. So that the view the website on that page to be untidy. to overcome this we can use function wordwrap () so that if there is a long word, then the word will automatically proceed to the next line.


[Code]
<Php
$ Comments = wordwrap ($ comment, 50, "\ n", 1);
echo $ comment;
?>
[/ Code]


with the functions above, each line in the comments just made up of 50 characters, and the end of the line ending with "\ n" or a string that indicates a new line.
3. Prevent HTML InjectionTo prevent the HTML tags is executed on the page comment, we can use htmlspecialchars () or strip_tags ().


[Code]
<? Php
$ Comment = htmlspecialchars ($ comment);
or
$ Comment = strip_tags ($ comment);
echo $ comment;
?>
[/ Code]
with the function htmlspecialchars () HTML tags are displayed view the first user input, but not executed. While the function strip_tags () will remove the HTML tags that the user input, and will not view the first display.


0 komentar:

Posting Komentar

Posting Komentar