Hello Everyone,

Please accept my simple and humble contribution. This script will validate if the user or visitor is a suspected spammer, by utilizing the stopforumspam API.

Example implementation

## example usage. These items can be from database or from form input. The choice of implementation is all up to you.

## the sample info. is an actual spammer based on the API response from stopforumspam. Notice the username did not return to be positive, but ip and email are both positive.

$ip = '';
$email = 'Kesten@gmail.com';
$userName = 'Tina Lupi';

$check = new SpamCheck($ip, $email, $userName);
$checkIp = ($check->validate_ip()? "This is spammer's IP" : "Not Spammer's IP");

## alternative validation 
// $checkIp = ($check->validate_ip($ip)? true : false);

echo $checkIp."<br/>";

$checkEmail = ($check->validate_email() ? "This is an spammer's email" : "Not Spammer's Email");

echo $checkEmail."<br/>";

$checkUserName = ($check->validate_user()? "This username appeared to be spammer's username" : "Not Spammer's username");

echo $checkUserName."<br/>";

The variables here are the ip, email, and username. Normally, spammers will use the same IP, email or username in any combinations like ip/email, email/username, ip/username.

To get the IP address of any visitor, we can use code below

 ## alternatively, we can also use getenv
 $ip = getenv('REMOTE_ADDR');

Email and username can be from your form processor. like...

 $email = $_POST['email'];
 $username = $_POST['username'];

The alternative validation can also be set like this

   $checkIp = ($check->validate_ip($ip)? true : false);
   ## redirect code here..


NOTE! There is no false positive here. If visitor ip validated to true, then it is more likely an spammer's ip. Case like my sample data above returns positive for IP and email, but false on username. The script is designed for you to decide which validation will you use.. ip?email?username?. I preferred validating by IP address, because spammer always use different email addresses and usernames, but the ip address sticks there for a while, before they generate another one. In fact, they do recycle ip addresses after months of dormancy.

## Provided to you by veedeoo or poorboy 2012
## Does not have any warranty of any kind.

class SpamCheck{
	private $ip = null;
	private $email = null;
	private $user = null;
	public function __construct($ip, $email, $user){
		$this->ip = $ip;
		$this->email = $email;
		$this->user = $user;
	private function xml_check($url){
	 $this->url = $url;
	 $this->doc = new DOMDocument();
	 $this->doc->load( $this->url );
	  foreach( $this->doc->getElementsByTagName( "response" ) as $record )
	  $types = $record->getElementsByTagName( "type" );
	  $this->type = $types->item(0)->nodeValue;
	  $appears = $record->getElementsByTagName( "appears" );
	  $this->appear = $appears->item(0)->nodeValue;
	  ## to extend the scope of this method e.g. number of times this ip/user/email has been registered, uncomment freqs below.
	  $freqs = $record->getElementsByTagName( "frequency" );
	  $this->freq = $freqs->item(0)->nodeValue;
	 return $this->appear;
	 ## to return results as an array just do it like this return array($this->appear, $this->freg,$this->type)
	public function validate_ip(){
	 $xml ='http://www.stopforumspam.com/api?ip='.$this->ip;
		return (self::xml_check($xml) == 'yes' ? true : false);
	public function validate_email(){
		$xml ='http://www.stopforumspam.com/api?email='.$this->email;
		return (self::xml_check($xml) == 'yes' ? true : false);
	public function validate_user(){
	 ## validate user
	 	$xml ='http://www.stopforumspam.com/api?username='.$this->user;
	    //$this->spam = (self::xml_check($xml) == 'yes' ? true : false);
	    //return $this->spam;
	    return (self::xml_check($xml) == 'yes' ? true : false);

## end of class..
Member Avatar


Simple Spammer Checker/validator Class

I got no idea how this works.

I don't have a forum.

Can I keep track my own IP so I can see how it works?