Page 1 of 1

captcha page checking

Posted: Mon Jan 25, 2010 6:53 am
by anp24
Hello,
I have a PHP page, which has captcha.php page called in for CAPTCHA. Now this captcha.php page has code
like

Code: Select all

@session_start();
$num    = array(1,2,3,4,5,6,7,8,9);
$words  = array("1","2","3","4","5","6","7","8","9");
$plus   = "+";
 
mt_srand((double)microtime()*1000000);
$first  = mt_rand(0,8);
$second = mt_rand(0,8);
 
$total = $num[$first] + $num[$second]; 
$showcode = $words[$first] . " + " . $words[$second] . "";
 
$_SESSION['total'] = $total;

now i am checking the captcha value in another page "sample_inc.php" which is included in the main page "main.php"

as

Code: Select all

if ($_SESSION["total"]!= $_POST["total"])
 {
$errors[]="You entered the wrong answer for the sum of two digits.";
        
    }
now if I open the page "main.php" in two or more different tabs in the IE browser. The captcha field will take the recent value i.e in $_SESSION['total'], irrespective of the sum of two numbers , otherwise it gives an error shown above.

How should I re-structure my code so that even If I open the same page in two different tabs of the browser, CAPTCHA will be unique and not interfere with the value of other tab.

Thank you

Re: captcha page checking

Posted: Mon Jan 25, 2010 7:04 am
by amargharat
I recommend to use recaptcha from recaptcha.net

download the latest pakage

It's very easy to implement

Re: captcha page checking

Posted: Mon Jan 25, 2010 11:23 pm
by anp24
Hello,
I have not written that code, I am just doing code review. How can I change the code written by someone else
Thanks