A Simple PHP captcha system. In order to use this code you simply need to
include save the captcha2.php file somewhere in your web tree, create a session variable to store the string you want as your captcha text and provide an img link to the captcha.
<?php
$_SESSION['CAPTCHA_STRING'] = 'random';
$_SESSION['CAPTCHA_COLOUR'] = 'blue,red,yellow,green';
?>
<img src = 'captcha2.php' alt='Security captcha' border=0>
<br>Enter the text requested in the above image:
<input type='text' name='form_captcha' value=''>
This will produce the following output in your page:
The code to check the text against the captcha when you are handling your post is remarkably simple:
if ($_POST['form_captcha'] === $_SESSION['CAPTCHA_STRING']) {
// it is good...
} else {
// sorry, bad answer
}
You can download the source code for captcha2.php and its required library pg_gd_wrappers.inc.php from here:
|