Jump to content

validate.. thing..


kellz

Recommended Posts

hey.. ok so I have made a small script to make sure that the person submitting is actually a human :-\ (the internet is freaky!) but it's kinda all going to hell and NOT doing what I wanted it to do, so obviously it hates me and doesn't want me to do anything right >:(

 

srand((double)microtime()*1000000); 
$x=rand(0,10);
$y=rand(0,10); 
$total = $x*$y;
$form = <<<HERE
<form name="form1" method="post" action="">
  <p>Please answer the following question to prove you are HUMAN. <br>
    $y / $x
    <input type="text" name="validate">
     <br>  
    <input type="submit" name="Submit" value="Submit">
  </p>
  </form>
HERE;
print $form;
if (isset($_POST['validate'])) {
    if ($_POST['validate'] == $total) {
        echo "ok your human!";
    } else {
        echo "GO TO HELL BOT!.";
    }
}

 

It does everything ok up until the point where i answer the sum, even if it's right it still tells me to "GO TO HELL" so I'm guessing that when I do "$total=$x*$y;" it's getting another random number from x & y instead of keeping the set it already had before i did the math.. I didn't know it could do this because that variable (or integer if you like) already has a value, how can it go and get another 1 ? kinda doesn't make much sense.. So yea.. I just need it to WORK and stop telling me to "GO TO HELL" lol ::)

 

thx :-*

Link to comment
Share on other sites

When the user presses the submit button you get a new pair of $x,$y. I think that the best way to keep the old values is by storing them in session variables. Should be something like this:

 

<?php

session_start();

if (isset($_POST['validate'])) {
    if ($_POST['validate'] == $_SESSION['xy']) {
        echo "ok your human!";
    } else {
        echo "GO TO HELL BOT!.";
    }
}

srand((double)microtime()*1000000); 
$x = rand(0,10);
$y = rand(0,10); 
$total = $x*$y;
$_SESSION['xy'] = $total;

$form = <<<HERE
<form name="form1" method="post" action="">
  <p>Please answer the following question to prove you are HUMAN. <br>
    $y x $x
    <input type="text" name="validate">
     <br>  
    <input type="submit" name="Submit" value="Submit">
  </p>
  </form>
HERE;
print $form;


?>

 

Also changed the "/" into "x" because that can confuse the user lol

 

Orio.

 

P.S.

1) You shouldn't include 0 into your random range.

2) Bots can easily make these maths, that's why this isn't the perfect bot filter....

Link to comment
Share on other sites

well $_POST['validate'] is user enter and $total is generated from your code how can a user know whats whats do you know what $total will be when your entering a form?

 

I guess you never tried it.. it knows because if the random number are like 7 and 8 then it gets the answer and stores it in $total, then the sum "7 * 8" is printed next to the input box so the user simply opens his eyes and looks at the sum and figures it out and puts the answer in the box^^ kinda simple.. simple but doesn't work..

Link to comment
Share on other sites

When the user presses the submit button you get a new pair of $x,$y. I think that the best way to keep the old values is by storing them in session variables. Should be something like this:

 

<?php

session_start();

if (isset($_POST['validate'])) {
    if ($_POST['validate'] == $_SESSION['xy']) {
        echo "ok your human!";
    } else {
        echo "GO TO HELL BOT!.";
    }
}

srand((double)microtime()*1000000); 
$x = rand(0,10);
$y = rand(0,10); 
$total = $x*$y;
$_SESSION['xy'] = $total;

$form = <<<HERE
<form name="form1" method="post" action="">
  <p>Please answer the following question to prove you are HUMAN. <br>
    $y x $x
    <input type="text" name="validate">
     <br>  
    <input type="submit" name="Submit" value="Submit">
  </p>
  </form>
HERE;
print $form;


?>

 

Also changed the "/" into "x" because that can confuse the user lol

 

Orio.

 

P.S.

1) You shouldn't include 0 into your random range.

2) Bots can easily make these maths, that's why this isn't the perfect bot filter....

 

that looks nice but it does this:

 

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at c:\program files\easyphp1-8\www\test.php:2) in c:\program files\easyphp1-8\www\test.php on line 4

 

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at c:\program files\easyphp1-8\www\test.php:2) in c:\program files\easyphp1-8\www\test.php on line 4

 

 

Link to comment
Share on other sites

Well I guess you modified the script or extended it.... Move the session_start() to the first line of the file.

 

Orio.

 

it.. modified itself. It works thank you sooo much *hugs* now i can catch those evil bots!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.