Here's a class I bodged together a few years ago to communicate with the
Stop Forum Spam API:
Code: <?php
class stop_forum_spam {
# Internal: Used to turn an XML response into a PHP array.
function process_response($response) {
$tags = array('appears', 'lastseen', 'frequency');
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_parse_into_struct($parser, $response, $vals, $index);
xml_parser_free($parser);
$result = array();
$type = 'unknown';
foreach ($vals as $val) {
if ($val['tag'] == 'type') {
$type = $val['value'];
} else {
if (in_array($val['tag'], $tags)) {
if (!isset($result[$type])) {
$result[$type] = array();
}
$result[$type][$val['tag']] = $val['value'];
}
}
}
return $result;
}
# Checks an IP address.
function check_ip($ip) { return stop_forum_spam::check(array('ip'=>$ip)); }
# Checks an email address.
function check_email($email) { return stop_forum_spam::check(array('email'=>$email)); }
# Checks a username.
function check_username($username) { return stop_forum_spam::check(array('username'=>$username)); }
# Checks multiple fields.
function check($fields) {
$url_components = array();
foreach ($fields as $k=>$v) {
$url_components[] = urlencode($k) . '=' . urlencode($v);
}
return stop_forum_spam::process_response(file_get_contents('http://www.stopforumspam.com/api?' . implode('&', $url_components)));
}
# Determines whether someone is a probable spammer or not.
function is_probable_spammer($fields) {
$is_passing_preprocessed_results = true;
foreach ($fields as $v) {
if (!is_array($v) || !isset($v['appears'])) {
$is_passing_preprocessed_results = false;
}
}
if (!$is_passing_preprocessed_results) $fields = stop_forum_spam::check($fields);
foreach ($fields as $v) {
if (is_array($v) && isset($v['appears']) && $v['appears'] == 'yes') return true;
}
return false;
}
}
?>
This is now used on the MaxCoderz forum. My inbox used to be flooded with activation requests from spammers attempting to use the forum; since I integrated this with the registration page I've only had one.
To integrate into phpBB 3, open includes/ucp/ucp_register.php and look for
Code: if (!check_form_key('ucp_register'))
{
$error[] = $user->lang['FORM_INVALID'];
}
Add the following code underneath:
Code: ### STOP FORUM SPAM BEGIN ###
require_once("{$phpbb_root_path}include/stop_forum_spam.$phpEx");
if (stop_forum_spam::is_probable_spammer(array(
'username'=>$data['username'],
'email'=>$data['email'],
'ip'=>$_SERVER['REMOTE_ADDR'],
))) {
$error[] = 'You appear to be a spammer.';
}
### STOP FORUM SPAM END ###
That's it. Try to register an account for fanlynne for a demo.