a:15:{s:4:"code";s:5:"LMyv5";s:10:"min_length";i:5;s:10:"max_length";i:5;s:11:"backgrounds";a:8:{i:0;s:66:"/drbd_disk1/home/www/lib/scaptcha/backgrounds/45-degree-fabric.png";i:1;s:61:"/drbd_disk1/home/www/lib/scaptcha/backgrounds/cloth-alike.png";i:2;s:62:"/drbd_disk1/home/www/lib/scaptcha/backgrounds/grey-sandbag.png";i:3;s:60:"/drbd_disk1/home/www/lib/scaptcha/backgrounds/kinda-jean.png";i:4;s:64:"/drbd_disk1/home/www/lib/scaptcha/backgrounds/polyester-lite.png";i:5;s:63:"/drbd_disk1/home/www/lib/scaptcha/backgrounds/stitched-wool.png";i:6;s:62:"/drbd_disk1/home/www/lib/scaptcha/backgrounds/white-carbon.png";i:7;s:60:"/drbd_disk1/home/www/lib/scaptcha/backgrounds/white-wave.png";}s:5:"fonts";a:1:{i:0;s:60:"/drbd_disk1/home/www/lib/scaptcha/fonts/times_new_yorker.ttf";}s:10:"characters";s:53:"ABCDEFGHJKLMNPRSTUVWXYZabcdefghjkmnprstuvwxyz23456789";s:13:"min_font_size";i:28;s:13:"max_font_size";i:28;s:5:"color";s:4:"#666";s:9:"angle_min";i:0;s:9:"angle_max";i:10;s:6:"shadow";b:1;s:12:"shadow_color";s:4:"#fff";s:15:"shadow_offset_x";i:-1;s:15:"shadow_offset_y";i:1;}
The following code will prepare a CAPTCHA image and keep the code in a session variable for later use:
<?php session_start(); include("simple-php-captcha.php"); $_SESSION['captcha'] = simple_php_captcha(); ?>
After the call to simple_php_captcha()
above,
$_SESSION['captcha']
will be something like this:
Array ( [code] => LMyv5 [image_src] => /j3/ksh01/lib/scaptcha/simple-php-captcha.php?_CAPTCHA&t=0.53202700+1750653096 )
To display the CAPTCHA image, create an HTML <img>
using
$_SESSION['captcha']['image_src']
as the src
attribute:
To verify the CAPTCHA value on the next page load (or in an AJAX request), test
against $_SESSION['captcha']['code']
. You can 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 $_SESSION['captcha'] = simple_php_captcha( array( 'min_length' => 5, 'max_length' => 5, 'backgrounds' => array(image.png', ...), 'fonts' => array('font.ttf', ...), 'characters' => 'ABCDEFGHJKLMNPRSTUVWXYZabcdefghjkmnprstuvwxyz23456789', 'min_font_size' => 28, 'max_font_size' => 28, 'color' => '#666', 'angle_min' => 0, 'angle_max' => 10, 'shadow' => true, 'shadow_color' => '#fff', 'shadow_offset_x' => -1, 'shadow_offset_y' => 1 )); >
session_start()
before
calling the simple_php_captcha()
function
$_SERVER['DOCUMENT_ROOT'] . '/' . [path-to-file]
)
simple_php_captcha()
in the global namespace
$_SESSION['simple-php-captcha']
session variable