quick question - captcha

Discussion in 'PHP' started by beedle, Jun 24, 2007.

  1. #1
    So I'm trying to make my own little rudimentary CAPTCHA... maybe this will never work, but I basically just tried to ask a simple question (what is 2 plus 2?)... then if the correct answer isn't in the form it gets flagged as false by the code I wrote below.


    		else if(document.signupForm.botcheck.value!='4')
    	{
    		flag=false;
    		alert("You have answered our spam prevention question incorrectly.  Please try again.");
    Code (markup):
    The problem is that it's not working worth a toot. Are the bots just looking in the code of the page and finding the above and going "Gee... I must need to put a 4 in this box."??

    How might I fix this? Load the checker from a separate PHP file or something over my head? (I so don't know PHP.)
     
    beedle, Jun 24, 2007 IP
  2. dp-user-1

    dp-user-1 Well-Known Member

    Messages:
    794
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #2
    You need to be using only PHP. That alert window won't stop a bot.
     
    dp-user-1, Jun 24, 2007 IP
  3. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #3
    NinjaNoodles is correct... the problem is that the bots don't run JavaScript and so won't even know that there was something 'stopping' the form submission.
     
    TwistMyArm, Jun 24, 2007 IP
  4. beedle

    beedle Peon

    Messages:
    67
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ok... thanks to both of you for that. That also explains why they could get away with not filling out some of the "required" fields. Alright... sounds over my head... guess I need to head over the the Buy Sell Trade area.
     
    beedle, Jun 24, 2007 IP
  5. dp-user-1

    dp-user-1 Well-Known Member

    Messages:
    794
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #5
    Not really, it's simpler than you think.

    In the PHP document that processes the form, put something like this:
    $captcha = $_POST['captcha']; //"captcha" being the name of your captcha form field
    if ($captcha != 4){
     exit("Check your math...");
    }
    PHP:
    That's just a very simple example. For added security you could use sessions and generate the math problems dynamicly. On images. Maybe even animated images (search for "animated gif captcha"). :)
     
    dp-user-1, Jun 25, 2007 IP
  6. beedle

    beedle Peon

    Messages:
    67
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    NinjaNoodles... thank you so much! I implemented that and tested it out... it works on me, now to see if it stops the bots too!

    Thanks!
     
    beedle, Jun 27, 2007 IP