kellz Posted November 3, 2007 Share Posted November 3, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/75918-validate-thing/ Share on other sites More sharing options...
rajivgonsalves Posted November 3, 2007 Share Posted November 3, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/75918-validate-thing/#findComment-384264 Share on other sites More sharing options...
Orio Posted November 3, 2007 Share Posted November 3, 2007 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.... Quote Link to comment https://forums.phpfreaks.com/topic/75918-validate-thing/#findComment-384268 Share on other sites More sharing options...
rajivgonsalves Posted November 3, 2007 Share Posted November 3, 2007 well said Orio I though about the session but did not know how to put it :-X Quote Link to comment https://forums.phpfreaks.com/topic/75918-validate-thing/#findComment-384270 Share on other sites More sharing options...
kellz Posted November 3, 2007 Author Share Posted November 3, 2007 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.. Quote Link to comment https://forums.phpfreaks.com/topic/75918-validate-thing/#findComment-384272 Share on other sites More sharing options...
kellz Posted November 3, 2007 Author Share Posted November 3, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/75918-validate-thing/#findComment-384278 Share on other sites More sharing options...
Orio Posted November 3, 2007 Share Posted November 3, 2007 Well I guess you modified the script or extended it.... Move the session_start() to the first line of the file. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/75918-validate-thing/#findComment-384280 Share on other sites More sharing options...
kellz Posted November 3, 2007 Author Share Posted November 3, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/75918-validate-thing/#findComment-384284 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.