The following code will prepare a CAPTCHA image and keep the code in a session variable for later use:
After the call to simple_php_captcha()
above,
$_SESSION['captcha']
will be something like this:
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:
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