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 = '23.19.152.194';
$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
$ip = $_SERVER['REMOTE_ADDR'];
## 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);
if($checkIp){
## 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.