captcha page checking

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anp24
Forum Newbie
Posts: 13
Joined: Wed Jul 11, 2007 6:34 am

captcha page checking

Post 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
amargharat
Forum Commoner
Posts: 82
Joined: Wed Sep 16, 2009 2:43 am
Location: Mumbai, India
Contact:

Re: captcha page checking

Post by amargharat »

I recommend to use recaptcha from recaptcha.net

download the latest pakage

It's very easy to implement
anp24
Forum Newbie
Posts: 13
Joined: Wed Jul 11, 2007 6:34 am

Re: captcha page checking

Post 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
Post Reply