You are here: C97net • 5.09 Security Functions
qEngine & Captcha
qEngine supports captcha in three easy steps:
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>
There is no comment. Why not be the first?