|
Page 3 of 3
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.
|