Property | Type | Description | |
---|---|---|---|
$audio_format | string | Type of audio file to generate (mp3 or wav) | |
$audio_path | string | Full path to the WAV files to use to make the audio files, include trailing /. Name Files [A-Z0-9].wav |
|
$background_directory | string | Scan this directory for gif, jpg, and png files to use as background images. A random image file will be picked each time. Change from null to the full path to your directory. i.e. var $background_directory = $_SERVER['DOCUMENT_ROOT'] . '/securimage/backgrounds'; Make sure not to pass a background image to the show function, otherwise this directive is ignored. |
|
$bgimg | resource | The background image resource | |
$charset | string | The character set for individual characters in the image. Letters are converted to uppercase. The font must support the letters or there may be problematic substitutions. |
|
$code | string | The code generated by the script | |
$code_entered | string | The code that was entered by the user | |
$code_length | integer | The length of the code to generate. | |
$correct_code | boolean | Whether or not the correct code was entered | |
$draw_lines_over_text | boolean | Draw the lines over the text. If fales lines will be drawn before putting the text on the image. |
|
$expiry_time | integer | The amount of time in seconds that a code remains valid. Any code older than this number will be considered invalid even if entered correctly. Any non-numeric or value less than 1 disables this functionality. |
|
$gd_font_file | mixed | Note: Use of GD fonts is not recommended as many distortion features are not available The GD font to use. Internal gd fonts can be loaded by their number. Alternatively, a file path can be given and the font will be loaded from file. |
|
$gd_font_size | integer | The approximate size of the font in pixels. This does not control the size of the font because that is determined by the GD font itself. This is used to aid the calculations of positioning used by this class. |
|
$gdbgcolor | integer | Color resource for image background color | |
$gdlinecolor | integer | Color resource for image line color | |
$gdmulticolor | array | Array of colors for multi colored codes | |
$gdsignaturecolor | integer | Color resource for image signature color | |
$gdtextcolor | integer | Color resource for image font color | |
$im | resource | The gd image resource. | |
$image_bg_color | Securimage_Color | The background color for the image as a Securimage_Color. |
|
$image_height | integer | The desired width of the CAPTCHA image. | |
$image_signature | Text to write at the bottom corner of captcha image | ||
$image_type | integer | The image format for output. Valid options: SI_IMAGE_PNG, SI_IMAGE_JPG, SI_IMAGE_GIF |
|
$image_width | integer | The desired width of the CAPTCHA image. | |
$iscale | integer | Internal scale factor for anti-alias @hkcaptcha | |
$line_color | string | Color of lines drawn over text | |
$multi_text_color | array | Array of Securimage_Colors which will be randomly selected for each letter. |
|
$num_lines | boolean | Draw vertical and horizontal lines on the image. | |
$perturbation | float | How much to distort image, higher = more distortion. Distortion is only available when using TTF fonts. |
|
$session_name | string | The session name to use if not the default. Blank for none | |
$signature_color | Securimage_Color | Color to use for writing signature text | |
$sqlite_database | string | Path to the file to use for storing codes for users. THIS FILE MUST ABSOLUTELY NOT BE ACCESSIBLE FROM A WEB BROWSER!! Put this file in a directory below the web root or one that is restricted (i.e. an apache .htaccess file with deny from all) If you cannot meet those requirements your forms may not be completely protected. You could obscure the database file name but this is also not recommended. |
|
$sqlite_handle | resource | Handle to SQLite database | |
$text_angle_maximum | integer | The minimum angle in degrees, with 0 degrees being left-to-right reading text. Higher values represent a counter-clockwise rotation. For example, a value of 90 would result in bottom-to-top reading text. |
|
$text_angle_minimum | integer | The minimum angle in degrees, with 0 degrees being left-to-right reading text. Higher values represent a counter-clockwise rotation. For example, a value of 90 would result in bottom-to-top reading text. This value along with maximum angle distance do not need to be very high with perturbation |
|
$text_color | Securimage_Color | The text color to use for drawing characters as a Securimage_Color. This value is ignored if $use_multi_text is set to true. Make sure this contrasts well with the background color or image. |
|
$text_transparency_percentage | integer | The percentage of transparency, 0 to 100. A value of 0 is completely opaque, 100 is completely transparent (invisble) |
|
$text_x_start | integer | The X-Position on the image where letter drawing will begin. This value is in pixels from the left side of the image. |
|
$tmpimg | resource | Temporary image for rendering | |
$ttf_file | string | The path to the TTF font file to load. | |
$use_gd_font | Use a gd font instead of TTF | ||
$use_multi_text | boolean | Set to true to use multiple colors for each character. | |
$use_sqlite_db | Use an SQLite database for storing codes as a backup to sessions. Note: Sessions will still be used |
||
$use_transparent_text | boolean | Set to true to make the characters appear transparent. | |
$use_wordlist | Use wordlist of not | ||
$wordlist_file | Create codes using this word list |
Method | Description | |
---|---|---|
Securimage ( ) |
Class constructor. Because the class uses sessions, this will attempt to start a session if there is no previous one. If you do not start a session before calling the class, the constructor must be called before any output is sent to the browser. |
|
addSignature ( ) | Print signature text on image | |
allocateColors ( ) | Allocate all colors that will be used in the CAPTCHA image | |
check ( string $code ) : boolean | Validate the code entered by the user. | |
checkCode ( ) : boolean | Check if the user entered code was correct | |
clearCodeFromDatabase ( ) | Delete a code from the database by ip address hash | |
createCode ( ) | Create a code and save to the session | |
distortedCopy ( ) |
Warp text from temporary image onto final image. Modified for securimage |
|
doImage ( ) | Generate and output the image | |
drawLines ( ) |
Draw random curvy lines over the image Modified code from HKCaptcha |
|
drawWord ( ) | Draw the CAPTCHA code over the image | |
frand ( ) : float | Generate random number less than 1 | |
generateCode ( integer $len ) : string | Generate a code | |
generateMP3 ( array $letters ) : string | Generate an mp3 file by concatenating individual files | |
generateWAV ( array $letters ) : string | Generate a wav file by concatenating individual files | |
getAudibleCode ( $format = 'wav' ) : string |
Get WAV or MP3 file data of the spoken code. This is appropriate for output to the browser as audio/x-wav or audio/mpeg |
|
getBackgroundFromDirectory ( ) : mixed | Return the full path to a random gif, jpg, or png from the background directory. | |
getCode ( ) : string | Get the captcha code | |
getCodeFromDatabase ( ) : string | Get stored captcha code from sqlite database based on ip address hash | |
getIPHash ( ) : string | Get hashed IP address of remote user | |
isCodeExpired ( $creation_time ) : boolean | Check a code to see if it is expired based on creation time | |
openDatabase ( ) : boolean | Open SQLite database | |
output ( ) | Output image to the browser | |
outputAudioFile ( ) |
Output audio file with HTTP headers to browser
$sound = new Securimage();
$sound->audio_format = 'mp3';
$sound->outputAudioFile();
|
|
purgeOldCodesFromDatabase ( ) | Purge codes over a day old from database | |
readCodeFromFile ( ) : mixed | Reads a word list file to get a code | |
saveCodeToDatabase ( ) : boolean | Save captcha code to sqlite database | |
saveData ( ) | Save the code in the session | |
scrambleAudioData ( &$data, $format ) |
Randomly modify the audio data to scramble sound and prevent binary recognition. Take care not to "break" the audio file by leaving the header data intact. |
|
setAudioPath ( $audio_directory ) : boolean |
Set the path to the audio directory. |
|
setBackground ( ) | Set the background of the CAPTCHA image | |
show ( string $background_image = "" ) | Generate a code and output the image to the browser. | |
validate ( ) | Validate the code to the user code |
public allocateColors ( ) |
$code = $_POST['code'];
if ($securimage->check($code) == false) {
die("Sorry, the code entered did not match.");
} else {
$valid = true;
}
public clearCodeFromDatabase ( ) |
public distortedCopy ( ) |
public drawLines ( ) |
public generateCode ( integer $len ) : string | ||
$len | integer | The code length |
return | string |
public generateMP3 ( array $letters ) : string | ||
$letters | array | Array of letters to build a file from |
return | string | MP3 file data |
public generateWAV ( array $letters ) : string | ||
$letters | array | Array of letters to build a file from |
return | string | WAV file data |
public getAudibleCode ( $format = 'wav' ) : string | ||
return | string | WAV or MP3 data |
public getBackgroundFromDirectory ( ) : mixed | ||
return | mixed | false if none found, string $path if found |
public getCodeFromDatabase ( ) : string | ||
return | string | captcha code |
public isCodeExpired ( $creation_time ) : boolean | ||
$creation_time | unix timestamp of code creation time | |
return | boolean | true if code has expired, false if not |
public openDatabase ( ) : boolean | ||
return | boolean | true if database was opened successfully |
$sound = new Securimage();
$sound->audio_format = 'mp3';
$sound->outputAudioFile();
public outputAudioFile ( ) |
public purgeOldCodesFromDatabase ( ) |
public readCodeFromFile ( ) : mixed | ||
return | mixed | false on failure, a word on success |
public saveCodeToDatabase ( ) : boolean | ||
return | boolean | true if code was saved, false if not |
public scrambleAudioData ( &$data, $format ) | ||
$data | Sound data in mp3 of wav format |
public setAudioPath ( $audio_directory ) : boolean | ||
return | boolean | true if the directory exists and is readble, false if not |
show('bg.jpg');
public string $audio_format | ||
return | string |
public string $audio_path | ||
return | string |
public string $background_directory | ||
return | string |
public string $charset | ||
return | string |
public string $code_entered | ||
return | string |
public int $code_length | ||
return | integer |
public bool $correct_code | ||
return | boolean |
public bool $draw_lines_over_text | ||
return | boolean |
public int $expiry_time | ||
return | integer |
public mixed $gd_font_file | ||
return | mixed |
public int $gd_font_size | ||
return | integer |
public int $gdbgcolor | ||
return | integer |
public int $gdlinecolor | ||
return | integer |
public array $gdmulticolor | ||
return | array |
public int $gdsignaturecolor | ||
return | integer |
public int $gdtextcolor | ||
return | integer |
public Securimage_Color $image_bg_color | ||
return | Securimage_Color |
public int $image_height | ||
return | integer |
public $image_signature |
public int $image_type | ||
return | integer |
public int $image_width | ||
return | integer |
public int $iscale | ||
return | integer |
public string $line_color | ||
return | string |
public array $multi_text_color | ||
return | array |
public bool $num_lines | ||
return | boolean |
public float $perturbation | ||
return | float |
public string $session_name | ||
return | string |
public Securimage_Color $signature_color | ||
return | Securimage_Color |
public string $sqlite_database | ||
return | string |
public resource $sqlite_handle | ||
return | resource |
public int $text_angle_maximum | ||
return | integer |
public int $text_angle_minimum | ||
return | integer |
public Securimage_Color $text_color | ||
return | Securimage_Color |
public int $text_transparency_percentage | ||
return | integer |
public int $text_x_start | ||
return | integer |
public string $ttf_file | ||
return | string |
public bool $use_multi_text | ||
return | boolean |
public $use_sqlite_db |
public bool $use_transparent_text | ||
return | boolean |