简体   繁体   中英

PHP contact avoid Spam

In this question I will take 2 parts of my problem.

PART 1:

I have a php + javascript validator form that sends an e-mail to my client if right rand numbers (generated by php) are validated by javascript. So far so good... The problem is that rand numbers are not sufficient to avoid SPAM (in fact, my client receives approx 20 per day e-mails by fake Adidas campaign). So, my idea comes from getting a rand number + 10 (forcing user to solve the calculation).

PART 2:

I am not preety sure what is the best way to solve this, but I think in this 3 options:

  1. Sum rand number inside php variable;
  2. Read rand number in javascript and sum 10 inside javascript;
  3. Read rand number generated by php and sum another rand number.

Here is my code, without sum:

PHP

$ran_num = rand(0,9999);
$exclude_check = "valid";

JAVASCRIPT

if (document.getElementById("spambox").value != "<?php echo $ran_num ?>") {
alert('<?php echo $spamerror_s5_qc ?>');
return false;
}

Simple honeypot example which is the most effective method i've seen that doesn't involve ip banning and stuff.

You'll want to put on your form a field you intend for users to NOT fill out. Then hide it with javascript on the frontend. Bots won't have javascript so they will see this field and fill it out. Make it named something that sounds important like 'required' or 'first_name' etc.

then on your PHP:

if($_POST['first_name']){
    //YA FILTHY BOT!
}
else{
     //process form
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM