print

Captcha

You are here: C97net5.09 Security Functions

qEngine & 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 at 07:00am
Last Updated: Jan-01-1970 at 07:00am

There is no comment. Why not be the first?

read more More Comments/Post Your Own

Account

Search

Tags

acp add all also any create default display don download easy echo etc features field file files folder form function includes information init kemana link list may module name need number own page php please qengine read require script set site skin time tpl url use user using version welcome