The following code will prepare a CAPTCHA image and keep the code in a session variable for later use:
<?php
session_start();
include("captcha.php");
$_SESSION['captcha'] = captcha();
?>
Dump of $_SESSION['captcha']:
To display the CAPTCHA image, create an HTML <img> using $_SESSION['captcha']['image_src']
as the src attribute:
'; ?>
To verify the CAPTCHA value, just test against the $_SESSION['captcha']['code']. Use
strtolower() or strtoupper() to perform a case-insensitive match.
Configuration is easy and all values are optional. To specify one or more options, do this:
<?php
// Showing default values
$_SESSION['captcha'] = captcha( array(
'min_length' => 5,
'max_length' => 5,
'png_backgrounds' => array('default.png', ...),
'fonts' => array('times_new_yorker.ttf', ...),
'characters' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
'min_font_size' => 24,
'max_font_size' => 30,
'color' => '#000',
'angle_min' => 0,
'angle_max' => 15,
'shadow' => true,
'shadow_color' => '#CCC',
'shadow_offset_x' => -2,
'shadow_offset_y' => 2
));
>
session_start() before calling the captcha() function