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.

Recommended Answers

Hi,

Did you read the Zend API Documentation on figlet? The answer to your question is right on the page.

Jump to Post

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 …

Jump to Post

All 5 Replies

Hi,

Did you read the Zend API Documentation on figlet? The answer to your question is right on the page.

I've tried many of the methods from this page and nothing.

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!
}

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... :((

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!';
            }

        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.