Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: CAPTCHA Alternative: Simple Math Question

  1. #1
    Join Date
    Jun 2009
    Location
    Houston
    Posts
    378

    Smile CAPTCHA Alternative: Simple Math Question

    Some people seem to have difficulty reading CAPTCHA. Here is an alternative that uses a simple math question along with formmail's built-in REVERSE_CAPTCHA feature.

    You can read up on formmail’s reverse captcha at the following location.

    http://www.tectite.com/fmdoc/attack_detection_reverse_captcha.php

    I modified it by replacing the bogus text normally used for the first reverse captcha field with the answer to a random math question. The second reverse captcha field is left empty and is hidden from the user on the form with css or some other method.

    You have two levels of security. First the user has to answer the math question correctly. Secondly, the second field has to be left empty. (Most spam bots fill in all of the fields.)

    On the form you will need a hidden field that has the default answer should the user not have JavaScript enabled. In my case the default question is 'What is two + three?' So, the default answer is '5'.
    Code:
    <input type="hidden" name="spam_ans" id="spam_ans" value= "5" />
    Add the following html just above your submit button:
    Code:
    <em>Please verify that you are a real person by answering the question below. (Required)</em>
    <div id="question">What is two + three?</div><input name="mgsfld1" type="text" value="" size="4" />
    Add the following JavaScript to your form page.
    Code:
    <script language="javascript" type="text/javascript">
      //Check for automated spambot
      var spam1=Math.floor(Math.random()*5);
      var spam2=Math.floor(Math.random()*5);
      var spam_result=spam1 + spam2;
      if (spam1==0){spam1="zero"};
      if (spam1==1){spam1="one"};
      if (spam1==2){spam1="two"};
      if (spam1==3){spam1="three"};
      if (spam1==4){spam1="four"};
      if (spam1==5){spam1="five"};
      if (spam2==0){spam2="zero"};
      if (spam2==1){spam2="one"};
      if (spam2==2){spam2="two"};
      if (spam2==3){spam2="three"};
      if (spam2==4){spam2="four"};
      if (spam2==5){spam2="five"};
      var mdiv=document.getElementById('question');
      mdiv.innerHTML="What is " + spam1 + " + " + spam2 +"?";
      var bdiv=document.getElementById('spam_ans');
      bdiv.value=spam_result;
    </script>
    Then in your formmail.php file setup reverse captcha similar to the following:
    Code:
    $ATTACK_DETECTION_REVERSE_CAPTCHA = array "mgsfld1"=>$spam_ans,"mgsfld2"=>"");
    Where 'mgsfld1' is the answer field and 'mgsfld2' is the empty field on the form.

    Hopefully someone will find this useful.

    Any comments on how effective this is versus normal captcha?


    p.s. this can also be made to work with autorespond but does require other changes.
    Last edited by jzieba; 16-Aug-2009 at 12:41 PM. Reason: ammendment

  2. #2
    Join Date
    Jun 2009
    Location
    Houston
    Posts
    378

    Post Re: CAPTCHA Alternative: Simple Math Question

    I decided to modify this strategy a little. The problem with using the math answer field as the first reverse captcha field is that if the user does not answer the question correctly, he gets formmail's spam notice. This can be solved with JavaScript but only if the user has js enabled.

    So, I implemented reverse captcha exactly per the documentation with two hidden fields.

    I then changed the name of the math answer field to "answer".
    Code:
    <em>Please verify that you are a real person by answering the question below. (Required)</em>
    <div id="question">What is two + three?</div><input name="answer" type="text" value="" size="4" />
    JavaScript code does not change.

    You can then use formmail to require the answer field and also validate that it is the correct answer. i.e. answer=spam_ans.

  3. #3
    Join Date
    Sep 2005
    Posts
    7

    Default Re: CAPTCHA Alternative: Simple Math Question

    Hey jzieba. I tried out your simple math question script to see if I could replace the CAPTCHA that I already use.

    I copied your code pretty much as it is but the code isn't working out. When I open up my JavaScript error console, it's telling me that the mdiv variable is equal to null so it's not actually affecting the div's content or the value of the hidden form.

    Could you help me out with this? If you have any examples you could show me on the web, that'd be cool too. Thanks a lot.

  4. #4
    Join Date
    Jun 2009
    Location
    Houston
    Posts
    378

    Post Re: CAPTCHA Alternative: Simple Math Question

    For the div that holds the question, did you give it an id?

    My form has the following code:

    <input type="hidden" name="spam_ans" id="spam_ans" value= "5" />
    <div id="question">What is two + three?</div>
    <input name="answer" type="text" value="" size="4" />

    My javascript code is:

    //Check for automated spambot
    var spam1=Math.floor(Math.random()*5);
    var spam2=Math.floor(Math.random()*5);
    var spam_result=spam1 + spam2;
    if (spam1==0){spam1="zero"};
    if (spam1==1){spam1="one"};
    if (spam1==2){spam1="two"};
    if (spam1==3){spam1="three"};
    if (spam1==4){spam1="four"};
    if (spam1==5){spam1="five"};
    if (spam2==0){spam2="zero"};
    if (spam2==1){spam2="one"};
    if (spam2==2){spam2="two"};
    if (spam2==3){spam2="three"};
    if (spam2==4){spam2="four"};
    if (spam2==5){spam2="five"};
    var mdiv=document.getElementById('question');
    mdiv.innerHTML="What is " + spam1 + " + " + spam2 +"?";
    var bdiv=document.getElementById('spam_ans');
    bdiv.value=spam_result;
    //end of spambot code

  5. #5
    Join Date
    Feb 2010
    Posts
    3

    Default Re: CAPTCHA Alternative: Simple Math Question

    Will this satisfy the requirements for auto respond?

  6. #6
    Join Date
    Jun 2009
    Location
    Houston
    Posts
    378

    Post Re: CAPTCHA Alternative: Simple Math Question

    You can make this work for autorespond. However, you still have to use verifyimg.php.

    You also have to make some configuration changes to Verifyimg.php to work with this method.

    Mail me privately if you want to know how.

  7. #7
    Join Date
    Mar 2010
    Posts
    2

    Default Re: CAPTCHA Alternative: Simple Math Question

    Hi,

    I followed jzieba's instructions and I also get the mdiv error. And I guess due also to the same error, the form gets submitted anyway, when I enter a wrong math answer.
    The script is at the head and I've configured formmail.php as required

    Perhaps you guys could look at my page html and see if you can see the source of the error?
    I would really appreciate your help.

    www.juandemarias.com/contact.html

    Thanks
    palosanto

  8. #8
    Join Date
    Jun 2009
    Location
    Houston
    Posts
    378

    Post Re: CAPTCHA Alternative: Simple Math Question

    I looked at your form and it seems to be working correctly.

  9. #9
    Join Date
    Mar 2010
    Posts
    2

    Unhappy Re: CAPTCHA Alternative: Simple Math Question

    Thanks for looking at it. Actually I used much different code with the same idea. The code in this thread didn't work and I gave up ...

    I don't use a formmail.php in my server but
    action=http://fp1.formmail.com/cgi-bin/fm192 instead

    So I guess
    reverse_captcha doesn't apply in this case ...

    Does this mean I don't need to have formmail.php in my server? Does it do anything?
    Here is where I get lost ... sorry.

    Thanks anyway

  10. #10

    Default Re: CAPTCHA Alternative: Simple Math Question

    Hey guys, thanks for this thread. It helped me out a lot!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Newbie question on open_basedir error
    By zenprofit in forum FormMail Subscription Support
    Replies: 14
    Last Post: 14-Feb-2005, 09:35 PM
  2. question about PHP version 4.3.8
    By djgotee in forum FormMail Subscription Support
    Replies: 4
    Last Post: 28-Nov-2004, 11:46 PM
  3. TARGET_EMAIL question
    By middleburyman in forum FormMail Subscription Support
    Replies: 1
    Last Post: 03-Sep-2004, 08:30 PM
  4. Uploading question
    By tray in forum FormMail Subscription Support
    Replies: 2
    Last Post: 11-Aug-2004, 09:31 PM
  5. at mangle / e-mail question
    By Ibis in forum FormMail Subscription Support
    Replies: 3
    Last Post: 25-Feb-2004, 02:59 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •