32,000+ SUBSCRIBERS CAN'T GO WRONG !!!

phpans
GET TOP ARTICLES, SNIPPETS, SCRIPTS IN YOUR INBOX FOR FREE!

Delivered by GET EMAIL UPDATES FeedBurner
We always respect your privacy and take protecting it seriously.
We won't Spam You

Create spam filter in PHP

, 0,
Create spam filter in PHP
Spam is harmfull for every website. Normally spam means link share, slang and other eligal activitis. Spam protector is very important for every website, we should check user comments. This article is about create a spam filter in php. Php always help us to make something new. Php is a wordwide opensource programming language. Anyone can customize their php website’s script if they wish. This is a great feature of php. In this article we are going to make this spam filter using php function. We create a function for detect spam and protect them. Cretae a function isspam($text) for detect spam. Then put spam words into this function.

function isspam($text)
{
$sfil[0] = "link";
$sfil[1] = "http";
$sfil[2] = "www";
$sfil[3] = "any slang";
$sfil[4] = "any word";
$sfil[5] = "any website";
$text = str_replace(" ", "", $text);
$text = strtolower($text);
for($i=0;$i<count($sfil);$i++)
{

$nosf = substr_count($text,$sfil[$i]);
if($nosf>0)
{
return true;
}
}

return false;
}

We can increase spam list by increasing $sfil variable. Php substar_count function find and detect spam word from our spam list in user input text. We also can create this function dynamicly and we can use spam protect words dynamicly. We can also create advance filter using some extar function. If we like that then we can use this function
<?php
function isspam($text,$user)
{
if(isadmin($user))
{
return false;
}
$string = $text;
$r1 = str_replace('~','',$string);
$r2 = str_replace('!','',$r1);
$r3 = str_replace('@','',$r2);
$r4 = str_replace('#','',$r3);
$r5 = str_replace('%','',$r4);
$r6 = str_replace('^','',$r5);
$r7 = str_replace('&','',$r6);
$r8 = str_replace('*','',$r7);
$r9 = str_replace('(','',$r8);
$r10 = str_replace(')','',$r9);
$r11 = str_replace('_','',$r10);
$r12 = str_replace('-','',$r11);
$r13 = str_replace('+','',$r12);
$r14 = str_replace('=','',$r13);
$r15 = str_replace('|','',$r14);
$r16 = str_replace('/','',$r15);
$r17 = str_replace(',','',$r16);
$r18 = str_replace('.','',$r17);
$r19 = str_replace('?','',$r18);
$r20 = str_replace('[','',$r19);
$r21 = str_replace(']','',$r20);
$r22 = str_replace('{','',$r21);
$r23 = str_replace('}','',$r22);
$r24 = str_replace('`','',$r23);
$r25 = str_replace(':','',$r24);
$r26 = str_replace('$','',$r25);
$r27 = str_replace('<','',$r26);
$r28 = str_replace('>','',$r27);
$r29 = str_replace('৳','',$r28);
$r30 = str_replace(' ','',$r29);
$r31 = str_replace('&quot;','',$r30);
$r32 = str_replace('&amp;','',$r31);
$r33 = str_replace('\\\\','',$r32);
$str = strtolower($r33);
$res = mysql_query("SELECT word FROM spamword_table");
while ($row = mysql_fetch_array($res))
{
$sites[] = $row[0];
}
for($i=0;$i<count($sites);$i++)
{
$nosf = substr_count($str,$sites[$i]);
if($nosf>0)
{
return true;
}
}
return false;
}
?>

This function at the first position we passed dual veriable isspam($text,$user). $text for check user input and $user for check user who request post new comment or new blog post. If this user admin then this fucntion will return this function output as not spam though input be spam word. In next step we replaced some special character with empty value for if user post a spam word with special character trickly then our advance spam filter replace it and detect spam word strongly. Our function creted and it’s ready to use. Now we are going to see how we use this function.
For that we are going to create a demo script like it.
<?php
$input = [‘input’];
If (isspam($input))
{
echo ‘This input is spam’;
}

else
{
echo ‘This inpu is not spam!!’;
}

That’s so easy. I hope this article is helpfull for you. I aslo hope you usnderstand this article, if you have any question about this artcile.

Download PDF
Signup & Get $25 Free
Is this article helpful for you?





captcha

  • Connect
  •       
Top
Create an free account and start learning & sharing! Sign Up