Captcha

qEngine supports captcha in three easy steps:

  1. Call qvc_init () to initiliaze qvc (qVisual Confirmation aka captcha).
  2. Display the captcha in the form.
  3. Compare user input captcha against stored value. If they are different, then user must re-enter the captcha.
function qvc_init ($num = 5)

Use this function to initialize qvc. $num is the number of digit to display, default is 5 digits.

function qvc_value ()

Use this function to call stored qvc value. qvc value is stored in user's cookies, encrypted by sha1(). Please remember, user input must be encrypted by sha1 before comparing!

To display the captcha image, use:

<img src="visual.php" alt="captcha" />

Example 1. test.php

<?php
require './includes/user_init.php';

$cmd = post_param ('cmd');

switch ($cmd)
{
    case 'process':
        $name = post_param ('name');
        $qvc = post_param ('qvc');
       
        // sha1 user input before comparing!
        if (sha1 ($qvc) != qvc_value()) msg_die ('echo', 'Invalid Captcha!');
        msg_die ('echo', 'Your name is '.$name);
    break;
   
    default:
        qvc_init ();
        $tpl = load_tpl ('test.tpl');
        $txt['main_body'] = quick_tpl ($tpl, $txt);
        flush_tpl ();
    break;
}
?>

test.tpl

<h1>Welcome to test page!</h1>
<form name="myform" action="test.php" method="post">
    <input type="hidden" name="cmd" value="process" />
    <p>Your name: <input type="text" name="name" /></p>
    <p>Captha: <img src="visual.php" alt="captcha" />
       <input type="text" name="qvc" /></p>
    <p><input type="submit" /></p>
</form>

Posted On: Aug-26-2010 @ 07:00am
Last Updated: Jan-01-1970 @ 07:00am

There is no comment. Why not be the first?

More Comments/Post Your Own

Advertisement

Online Users

There are 121 users online.

Connect

Connect with us on Facebook

Newsletter

Subscribe to our newsletter for the latest updates and exciting promotions!