Headless PHP Drupal script deletes spam zombie user accounts
By Liraz Siri - 4 comments | Latest by Ronny PaulFor for the last few months automatic bots have been creating hundreds of zombie accounts per day on the TurnKey web site. I'm not sure why they bother. I assume it has something to do with spamming, but they never log in. Besides, spam almost never gets past our content filter (Mollom) and when it does we always nuke it. Zero tolerance.
Brains...
Meanwhile these zombie accounts are polluting my precious database, and that bothers me. Besides, call me prejudiced, but I just hate zombies. You're either alive or you're dead. Pick a side!
We could enable CAPTCHA but we'd rather make user registration more complicated only as a last resort.
So I wrote a quick and dirty script to delete all 38489 zombie accounts on the TurnKey Linux web site. As you can see below my definition of a zombie user is one that has never logged in or accessed the site, and is over a week old.
<?php
error_reporting(E_ALL);
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
print "<pre>";
$results = db_query("select uid, name, mail, access, created, login
FROM users WHERE created != 0 AND login=0 AND access=0");
$i = 0;
while ($result = db_fetch_object($results)) {
print_r($result);
$daysago = ((time() - $result->created) / (24 * 60 * 60));
printf("created = %s, days ago = %d\n",
date("Y-m-d", $result->created), $daysago);
print "n";
if($daysago < 7)
continue;
user_delete(NULL, $result->uid);
$i += 1;
}
print "COUNT: $in";
print "</pre>";
?>
Hope somebody else finds this useful!
Comments
Small correction to the script
I noticed two things in the script which probably were intended slightly different. Even though it wouldn't affect the workings, it affects the clarity of the output - which goes to how we manually confirm that it actually does work:
Weird quoting issue
Where would you place this
Would you place this is the Drupal root directory?
I too have had this problem and periodically deleted them by hand!
Useful scripts
Can I replace this correction scripts to original script.? That's really useful scripts in drupal scripts. Drupal Development India
Post new comment