
Quickstart Guide
In the desired position on your form, add the following code to display the CAPTCHA image:
<img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image" />
Next, add the following HTML code to create a text input box:
<input type="text" name="captcha_code" size="10" maxlength="6" />
Note: You can change the maxlength and size properties to match your image settings.
The next step is optional, but can be useful to your users if they cannot read the code they are given.
The following code can be used to dynamically reload the CAPTCHA image without having to reload the page. Add this in a convenient location near the CAPTCHA image.
<a href="#" onclick="document.getElementById('captcha').src = '/securimage/securimage_show.php?' + Math.random(); return false">Reload Image</a>
Open the PHP file that processes the form data after submission.
You can find this by looking at the action value inside your <form> tag.
On line 1 of the file, add the following code:
<?php session_start(); ?>
The next few steps will vary depending on how form validation is handled in your code.
To check if the code is correct, we will make a call to the Securimage class. The following php code should be integrated into the script that processes your form near any error checking that takes place. It should be between <?php ?> tags.
include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
$securimage = new Securimage();
Next we will actually check to see if the code was correct.
if ($securimage->check($_POST['captcha_code']) == false) {
// the code was incorrect
// handle the error accordingly with your other error checking
// or you can do something really basic like this
die('The code you entered was incorrect. Go back and try again.');
}
常规属性:
$img->image_width = 275;
$img->image_height = 90;
$img->perturbation = 0.9; // 1.0 = high distortion, higher numbers = more distortion
$img->image_bg_color = new Securimage_Color("#0099CC");
$img->text_color = new Securimage_Color("#EAEAEA");
$img->text_transparency_percentage = 65; // 100 = completely transparent
$img->num_lines = 8;
$img->line_color = new Securimage_Color("#0000CC");
$img->signature_color = new Securimage_Color(rand(0, 64), rand(64, 128), rand(128, 255));
$img->image_type = SI_IMAGE_PNG;
$img->show('backgrounds/bg5.jpg');
附件下载:
Securimage 2.0.1