0

Hi all.

For 3 days I have searched the web to find out how it works, unfortunatelly with no success.

I need to compare the encrypted haptcha code with my text, both of them sent by a form.

if(!isset($_POST['my_text'])) {

            $view = new Zend_View();

            $captcha = new Zend_Captcha_Figlet(array(
                'name' => 'foo',
                'wordLen' => 6,
                'timeout' => 300,
            ));

            $captcha_code = $captcha->generate();
            $captcha_image = $captcha->render($view);

            echo '<form method="post" action="">';
            echo $captcha_image;
            echo '<input type="text" name="my_text" />';
            echo '<input type="hidden" name="captcha_code" value="'.$captcha_code.'" />';
            echo '<input type="submit" value="Submit" />';
            echo '</form>';

        } else {

            echo $_POST['my_text'].'<br />';            
            echo $_POST['captcha_code'].'<br />';

        }

Please help how can I compare $_POST['my_text'] and $_POST['captcha_code'].

Thank you.

2
Contributors
5
Replies
7
Views
4 Years
Discussion Span
Last Post by eburlea
1

Here is a good example of validation and comparison. Pay attention to the commented part of the script. Most importantly on the id.

I am assuming that your script should give you a captcha "foo"? , and therefore the my_text should validate to foo and so as the $captcha_code = $captcha->generate() which is derived from the array of figlet. The validation and comparison of the two is the same as what is stated on the link I have provided above. Here is the snippet from the zend site.

if ($captcha->isValid($_POST['foo'], $_POST)) {
// Validated!
}

so, in your case it can be something like this

if ($captcha->isValid($_POST['my_text'], $_POST)) {
// Validated!
}

Edited by veedeoo: info added

0

Thank you for reply. I inserted your code in my file:

if(!isset($_POST['my_text'])) {

            //$view = new Zend_View();

            $captcha = new Zend_Captcha_Figlet(array(
                'name' => 'foo',
                'wordLen' => 6,
                'timeout' => 300,
            ));

            $captcha_code = $captcha->generate();
            //$captcha_image = $captcha->render($view);
            $captcha_image = $captcha->render();

            echo '<form method="post" action="">';
            echo $captcha_image;
            echo '<input type="text" name="my_text" />';
            echo '<input type="hidden" name="captcha_code" value="'.$captcha_code.'" />';
            echo '<input type="submit" value="Submit" />';
            echo '</form>';

        } else {

            echo $_POST['my_text'].'<br />';
            echo $_POST['captcha_code'].'<br />';

            if ($captcha->isValid($_POST['my_text'], $_POST)) {
                // Validated!
            }

        }

...and I've got the following result:

VEKOVI
812084cdd6af6fe2efa592c071923b60

Notice: Undefined variable: captcha in /var/www/soccerstatistics/application/controllers/SoccerController.php on line 328

Fatal error: Call to a member function isValid() on a non-object in /var/www/soccerstatistics/application/controllers/SoccerController.php on line 328

I have tried other changes also, but nothing. I need to know the exact mechanism of how it works, that is why I posted here. I cannot figure it out... :((

0

One friend helped me to find out the solution:

$captcha = new Zend_Captcha_Figlet(array(
                'name' => 'foo',
                'wordLen' => 6,
                'timeout' => 300,
            ));

        if(!isset($_POST['my_text'])) {

            $captcha_code = $captcha->generate();
            $captcha_image = $captcha->render();

            echo '<form method="post" action="">';
            echo $captcha_image;
            echo '<input type="text" name="my_text" />';
            echo '<input type="hidden" name="captcha_code" value="'.$captcha_code.'" />';
            echo '<input type="submit" value="Submit" />';
            echo '</form>';

        } else {

            echo $_POST['my_text'].'<br />';
            echo $_POST['captcha_code'].'<br />';

            if ($captcha->isValid(array('id' => $_POST['captcha_code'],'input' => $_POST['my_text']))) {
                echo 'Validated!';
            } else {
                echo 'Not validated!';
            }

        }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.