Stop Forum Spam Checking Function
Posted: Sun May 15, 2011 11:31 pm
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.jacek wrote:This is an archive post, any discussion should take place here http://betterphp.co.uk/board/viewtopic.php?f=5&t=130
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; }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.
var_dump(known_spammer(null, null, '1.2.3.4'));Or to check all three things,
var_dump(known_spammer('jacek', 'test1@betterphp.co.uk', '1.2.3.4'));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