Stop Forum Spam Checking Function

Code that the staff think is particularly good will be copied here.
Locked
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Stop Forum Spam Checking Function

Post by jacek »

jacek wrote:This is an archive post, any discussion should take place here viewtopic.php?f=5&t=130


This function will tell you if any of the user information you give it appears in the stopforumspam.com database, could be useful for registration forms, guestbooks etc.

[syntax=php]function known_spammer($username = null, $email = null, $ip = null){
if ($username !== null){
$query['username'] = $username;
}

if ($email !== null){
$query['email'] = $email;
}

if ($ip !== null){
$query['ip'] = $ip;
}

if (empty($query)){
return false;
}

$data = file_get_contents('http://www.stopforumspam.com/api?' . http_build_query($query) . '&f=serial');
$data = unserialize($data);

if ($data['success'] !== 1){
return false;
}

unset($data['success']);

foreach ($data as $check){
if ($check['appears'] == '1'){
return true;
}
}

return false;
}[/syntax]

Each parameter is optional and should be replaced with null if you want to skip it. for example to check if an IP is in the database.

[syntax=php]var_dump(known_spammer(null, null, '1.2.3.4'));[/syntax]

Or to check all three things,

[syntax=php]var_dump(known_spammer('jacek', 'test1@betterphp.co.uk', '1.2.3.4'));[/syntax]

There is a limit to how many times you can use this form the same IP, that limit is 20,000 so I doubt it will cause many problems :lol:
Image
Locked