Hide-form-if-IP-is-a-Spammer

Hide form if IP is a Spammer

The evolution of bots and spammers makes Inbound Marketing and Lead Generation a huge headache for popular sites. These “spiders” will crawl into any available input field and try to attack. I’m going to cover a new technique to help combat this new wave of insect warfare. Using the www.StopForumSpam.com API to check if our visitor has had their IP reported.

UPDATE: I will update this article with code snippets for various frameworks as I finish them. As of today we are going to cover plain PHP code, and the MODX Evolution eForm plugin.

My theory attempts to help in 2 areas.

  1. Minimizing the number of actual emails by hiding the form altogether.
  2. Suggesting a phone call to get immediate help and hopefully a phone lead instead.

Hide eForm on MODX Evolution if IP is a spammer

Follow the normal install procedures for eForm.

Go to your Manager -> Elements -> Snippets -> eForm and find:

$output = eForm($modx,$params);

Replace with:

//original line $output = eForm($modx,$params); //start my spam control $visitorip = $_SERVER["REMOTE_ADDR"]; $SFSapiurl = "http://www.stopforumspam.com/api?&ip=".$visitorip."&f=json"; $SFSdata = @file_get_contents($SFSapiurl); $SFSjson = json_decode($SFSdata,true); //make sure it works print_r($SFSjson); if($SFSjson["ip"]["appears"] > 1){ $output = "Your IP Address is on the StopForumSpam.com list, therefore we are not allowing you to use the contact form. If you believe this to be inaccurate. You can call us at 727-289-6549, and we will check the reason your listed."; } else { $output = eForm($modx,$params); }

Edit the OUTPUT to your own message and that’s it for this tip. I also highly recommend you do the “getServer” snippet upgrade to your eForm so you can report the IP just in case someone manages to slip through.

Hide FormIt on MODX Revolution if IP is a spammer

Same Principle as above. Install FormIt through the Package management.

Go to your Elements -> Snippets -> FormIt and wrap the code there like above.

Plain PHP Code

Create a file called “ip-check.php”. From your contact form page add this to the top:

require_once('ip-check.php');

ip-check.php contains:

<? $visitorip = $_SERVER["REMOTE_ADDR"]; $SFSapiurl = "http://www.stopforumspam.com/api?&ip=".$visitorip."&f=json"; $SFSdata = @file_get_contents($SFSapiurl); $SFSjson = json_decode($SFSdata,true); ?>

In your contact form php page:

<? if($SFSjson["ip"]["appears"] > 1){ $output = "Your IP Address is on the StopForumSpam.com list, therefore we are not allowing you to use the contact form. If you believe this to be inaccurate. You can call us at 727-289-6549, and we will check the reason your listed."; } else { ?> <form>all your fields here</form> < } >

You can still use other means of input validation with this. It just provides an extra layer of protection for already known spammers. It only works if we all participate so add your known spam email offenders to the list at www.StopForumSpam.com.

Derek Corneau

Written by:

Derek’s positive attitude makes him an invaluable asset to Revital Agency. As Web Coordinator, he handles any online creative efforts and social media interactions with ease.

SUBSCRIBE TO THE REVITAL AGENCY BLOG

GET FREE MARKETING TIPS & UNCOVER
THE BEST WAYS TO GROW YOUR BUSINESS.

Enter your email address below: