Looking at the code, it appears you have to call this function twice, once to output the question and once to output the answer. The problem is that the first two lines of code...
Code:
$x = rand(1,10);
$y = rand(1,10);
...run both times, both for the question and the answer. So when you call verification('answer'), a new set of random numbers is generated.
I can think of two solutions: You could rework the verification script so that it only needs to call this function once. Or you could store $x and $y in global scope, and move the rand() calls inside the if($foo == 'question'){...} block. (This assumes both functions calls are done by the same script on the same page--if that's not true, you'll need to work with sessions.)
However, a much simpler (and more secure) option would be to not write this code yourself in the first place. I'm not sure what you're trying to verify, but Google's reCAPTCHA service might work for you: http://www.google.com/recaptcha
__________________
Please login or register to view this content. Registration is FREE
I solve code problems, browser compatibility (including IE 6), Wordpress trouble, the works.
Last edited by Crimson; 10-23-2010 at 04:32 PM..
|