Dealing With Forum & Mailing List Spam
Written by Ian Elliot   
Friday, 04 January 2013
Article Index
Dealing With Forum & Mailing List Spam
Stop Forum Spam API in PHP
Complete program

Complete program

Putting all this together gives:

<?php
 $number=$_GET["n"];
 try {
  $dbh = new PDO('mysql:host=localhost;
         dbname='MyDATABASE',
         'MyUSERNAME',
         'MyPASSWORD');
  $rows=$dbh->query('SELECT email from MyUsers
           ORDER BY id DESC  LIMIT '.$number);
  $count=0;
  foreach($rows as $row) {
    $email=$row[email];         
    $result= checkSpam($email);
    echo $email;
    if($result) echo "X";
    echo "<BR/>";
    if($result){
        $count++;
        $dbh->query('DELETE FROM MyUsers
          WHERE email ="'.$row[email].'"');
    }
    myFlush();
  }
    $dbh = null;
    echo $count;
 } catch (PDOException $e) {
    print "Error!: ".
          $e->getMessage()."<br/>";
    die();
}

function myFlush() {
   echo(str_repeat(' ', 256));
   if (@ob_get_contents()) {
       @ob_end_flush();
   }
   flush();
}

function checkSpam($email){
 $baseURL =
       'http://www.stopforumspam.com/api';
 $query["email"]=$email;
 $query["f"]="json";
 $url = $baseURL.'?'.
         http_build_query($query, '', '&');
 $json= file_get_contents( $url );
 $result = json_decode($json);
 $spammer=false;
 if($result->success)
 {
  $spammer=$result->email->appears;
 };
  return $spammer;
}
?>

You can customize the program to be cleverer if you want to and this is certainly just a starting point.

In use the program deletes aproximately 50% of new signups but there are roughly 25% of the remainder that look a lot like spam addresses. The task of keeping spam under control is difficult.

If you would like the code for this article register with I Programmer and visit the codebin.

 

Banner

More Information

www.stopforumspam.com

 

To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin,  or sign up for our weekly newsletter.

 

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info

 



Last Updated ( Tuesday, 08 January 2013 )