...

View Full Version : Simple spam removal.



idalatob
09-05-2007, 02:47 PM
Often when coders making additions to a database through user input they forget to ACTUALLY stop invalid input. This is a simple script (its designed to be simple) to help with spammers. (you could make it a function too)

No function

<?php
$message = "<hm>What ever you want it to be.</hm>";
$message1 = strip_tags($message);
if ((strlen($message)) > (strlen($message1))){
$error = true;
echo("NO");
} else {
//proceed with database addition
echo("yes");
}
?>

As a function

<?php
function checkInput($message){
$message1 = strip_tags($message);
if ((strlen($message)) > (strlen($message1))){
$error = true;
return false;
} else {
return true;
}
}
?>

Mwnciau
09-05-2007, 02:52 PM
If someone wanted to post some html code on a forum etc. using this would stop them posting, it would be easier to just use htmlspecialchars() which replaces < with &lt; and > with &gt;, so any html code will be shown rather than used in the page.

idalatob
09-05-2007, 03:50 PM
If someone wanted to post some html code on a forum etc. using this would stop them posting, it would be easier to just use htmlspecialchars() which replaces < with &lt; and > with &gt;, so any html code will be shown rather than used in the page.

true ... true. However this script is specifically for stopping any html code whatsoever. Have you ever seen forums destroyed by advertising? Its mainly because they strip tags yet show the message anyway. So you still get porn adds and stuff.

rafiki
09-05-2007, 03:59 PM
function remove_html_chars($string){
$html_chars = array(<, > ,e,t,c);
$string = preg_replace("$html_chars", '', $string);
return $string;
}

tihs would simply remove any charicters that you put in html_chars

student101
03-14-2009, 08:54 PM
$message = "<hm>What ever you want it to be.</hm>";
$message1 = strip_tags($message);
if ((strlen($message)) > (strlen($message1))){

I am not the best coder but a bit confused by this line;

if ((strlen($message)) > (strlen($message1))){
Is that just a checking method to continue with the if then }else{
I don't think that having the if then else is needed, it will be greater than the stripped message.


$message = "<html>What ever you want it to be.</html>";
$message1 = strip_tags($message);
//proceed with database addition



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum