SI_IMAGE_JPEG
SI_IMAGE_JPEG
Constant for rendering captcha as a JPEG image
Securimage CAPTCHA Class.
A class for creating and validating secure CAPTCHA images and audio.
The class contains many options regarding appearance, security, storage of captcha data and image/audio generation options.
$image_bg_color : \Securimage_Color
The background color of the captcha
$text_color : \Securimage_Color
The color of the captcha text
$line_color : \Securimage_Color
The color of the lines over the captcha
$noise_color : \Securimage_Color
The color of the noise that is drawn
$signature_color : \Securimage_Color
The color of the signature text
$use_database : bool
Use a database backend for code storage.
Provides a fallback to users with cookies disabled. Required when using captcha IDs.
todo |
---|
$skip_table_check : bool
Whether or not to skip checking if Securimage tables exist when using a database.
Turn this to true once database functionality is working to improve performance.
todo |
---|
$database_driver : string
Database driver to use for database support.
Allowable values: mysql, pgsql, sqlite. Default: sqlite
todo |
---|
$database_host : string
Database host to connect to when using mysql or postgres
On Linux use "localhost" for Unix domain socket, otherwise uses TCP/IP
Does not apply to SQLite
todo |
---|
$database_user : string
Database username for connection (mysql, postgres only) Default is an empty string
todo |
---|
$database_pass : string
Database password for connection (mysql, postgres only) Default is empty string
todo |
---|
$database_name : string
Name of the database to select (mysql, postgres only)
todo |
---|
$database_table : string
Database table where captcha codes are stored
Note: Securimage will attempt to create this table for you if it does not exist. If the table cannot be created, an E_USER_WARNING is emitted
todo |
---|
$database_file : string
Fully qualified path to the database file when using SQLite3.
This value is only used when $database_driver == sqlite and does not apply when no database is used, or when using MySQL or PostgreSQL.
On *nix, file must have permissions of 0666.
Make sure the directory containing this file is NOT web accessible
todo |
---|
$captcha_type : int
The type of captcha to create.
Either alphanumeric based on charset, a simple math problem, or an image consisting of 2 words from the word list.
todo |
---|
$namespace : string
The captcha namespace used for having multiple captchas on a page or to separate captchas from differen forms on your site.
Example:
<?php
// use <img src="securimage_show.php?namespace=contact_form">
// or manually in securimage_show.php
$img->setNamespace('contact_form');
// in form validator
$img->setNamespace('contact_form');
if ($img->check($code) == true) {
echo "Valid!";
}
todo |
---|
$ttf_file : string
The TTF font file to use to draw the captcha code.
Leave blank for default font AHGBold.ttf
todo |
---|
$wordlist_file : string
The path to the wordlist file to use.
Leave blank for default words/words.txt
todo |
---|
$background_directory : string
The directory to scan for background images, if set a random background will be chosen from this folder
todo |
---|
$sqlite_database : string
No longer used
The path to the SQLite database file to use
todo |
---|
$audio_path : string
The path to the audio files to be used for audio captchas.
Can also be set in securimage_play.php
Example:
$img->audio_path = '/home/yoursite/public_html/securimage/audio/en/';
todo |
---|
$audio_use_sox : bool
Use SoX (The Swiss Army knife of audio manipulation) for audio effects and processing.
Using SoX should make it more difficult for bots to solve audio captchas
todo |
---|
todo |
---|
$audio_noise_path : string
The path to the directory containing audio files that will be selected randomly and mixed with the captcha audio.
todo |
---|
$audio_use_noise : bool
Whether or not to mix background noise files into captcha audio
Mixing random background audio with noise can help improve security of audio captcha.
Default: securimage/audio/noise
since | |
---|---|
todo |
$audio_mix_normalization : float
The method and threshold (or gain factor) used to normalize the mixing with background noise.
See http://www.voegler.eu/pub/audio/ for more information.
Default: 0.6
Valid:
>= 1
Normalize by multiplying by the threshold (boost - positive gain).
A value of 1 in effect means no normalization (and results in clipping).
<= -1
Normalize by dividing by the the absolute value of threshold (attenuate - negative gain).
A factor of 2 (-2) is about 6dB reduction in volume.
[0, 1) (open inverval - not including 1)
The threshold above which amplitudes are comressed logarithmically.
e.g. 0.6 to leave amplitudes up to 60% "as is" and compressabove.
(-1, 0) (open inverval - not including -1 and 0)
The threshold above which amplitudes are comressed linearly.
e.g. -0.6 to leave amplitudes up to 60% "as is" and compress above.
since | |
---|---|
todo |
$degrade_audio : bool
Whether or not to degrade audio by introducing random noise.
Current research shows this may not increase the security of audible captchas.
Default: true
since | |
---|---|
todo |
$audio_gap_min : float
Minimum delay to insert between captcha audio letters in milliseconds
since | |
---|---|
todo |
$audio_gap_max : float
Maximum delay to insert between captcha audio letters in milliseconds
since | |
---|---|
todo |
$securimage_path : string
Absolute path to securimage directory.
This is calculated at runtime
todo |
---|
$display_value : string
Alternate text to draw as the captcha image text
A value that can be passed to the constructor that can be used to generate a captcha image with a given value.
This value does not get stored in the session or database and is only used when calling Securimage::show().
If a display_value was passed to the constructor and the captcha image is generated, the display_value will be used as the string to draw on the captcha image.
Used only if captcha codes are generated and managed by a 3rd party app/library
todo |
---|
todo |
---|
$tmpimg : resource
A temporary GD image resource of the captcha image for distortion
todo |
---|
$code : string
The captcha challenge value.
Either the case-sensitive/insensitive word captcha, or the solution to the math captcha.
todo |
---|
$code_display : string
The display value of the captcha to draw on the image
Either the word captcha or the math equation to present to the user
todo |
---|
$captcha_code : string
Captcha code supplied by user [set from Securimage::check()]
todo |
---|
$_timeToSolve : int
Time (in seconds) that the captcha was solved in (correctly or incorrectly).
This is from the time of code creation, to when validation was attempted.
todo |
---|
$no_exit : bool
Flag that can be specified telling securimage not to call exit after generating a captcha image or audio file
todo |
---|
$no_session : bool
Flag indicating whether or not a PHP session should be started and used
todo |
---|
$send_headers : bool
Flag indicating whether or not HTTP headers will be sent when outputting captcha image/audio
todo |
---|
todo |
---|
todo |
---|
todo |
---|
$gdsignaturecolor : resource
The GD color resource for the signature text color
todo |
---|
__construct(array $options)
Create a new securimage object, pass options to set in the constructor.
The object can then be used to display a captcha, play an audible captcha, or validate a submission.
array | $options | Options to initialize the class. May be any class property.
|
todo |
---|
getPath() : string
Return the absolute path to the Securimage directory.
The path to the securimage base directory
todo |
---|
getCaptchaId(bool $new, array $options) : null|string
Generate a new captcha ID or retrieve the current ID (if exists).
bool | $new | If true, generates a new challenge and returns and ID. If false, the existing captcha ID is returned, or null if none exists. |
array | $options | Additional options to be passed to Securimage. $options must include database settings if they are not set directly in securimage.php |
Returns null if no captcha id set and new was false, or the captcha ID
todo |
---|
checkByCaptchaId(string $id, string $value, array $options) : bool
Validate a captcha code input against a captcha ID
string | $id | The captcha ID to check |
string | $value | The captcha value supplied by the user |
array | $options | Array of options to construct Securimage with. Options must include database options if they are not set in securimage.php |
true if the code was valid for the given captcha ID, false if not or if database failed to open
todo |
---|
show(string $background_image)
Generates a new challenge and serves a captcha image.
Appropriate headers will be sent to the browser unless the send_headers option is false.
string | $background_image | The absolute or relative path to the background image to use as the background of the captcha image.
|
todo |
---|
check(string $code) : bool
Checks a given code against the correct value from the session and/or database.
string | $code | The captcha code to check
|
true if the given code was correct, false if not.
todo |
---|
getCaptchaHtml(array $options) : string
Returns HTML code for displaying the captcha image, audio button, and form text input.
Options can be specified to modify the output of the HTML. Accepted options:
'securimage_path':
Optional: The URI to where securimage is installed (e.g. /securimage)
'image_id':
A string that sets the "id" attribute of the captcha image (default: captcha_image)
'image_alt_text':
The alt text of the captcha image (default: CAPTCHA Image)
'show_audio_button':
true/false Whether or not to show the audio button (default: true)
'show_refresh_button':
true/false Whether or not to show a button to refresh the image (default: true)
'show_text_input':
true/false Whether or not to show the text input for the captcha (default: true)
'refresh_alt_text':
Alt text for the refresh image (default: Refresh Image)
'refresh_title_text':
Title text for the refresh image link (default: Refresh Image)
'input_id':
A string that sets the "id" attribute of the captcha text input (default: captcha_code)
'input_name':
A string that sets the "name" attribute of the captcha text input (default: same as input_id)
'input_text':
A string that sets the text of the label for the captcha text input (default: Type the text:)
'input_attributes':
An array of additional HTML tag attributes to pass to the text input tag (default: empty)
'image_attributes':
An array of additional HTML tag attributes to pass to the captcha image tag (default: empty)
'error_html':
Optional HTML markup to be shown above the text input field
'namespace':
The optional captcha namespace to use for showing the image and playing back the audio. Namespaces are for using multiple captchas on the same page.
array | $options | Array of options for modifying the HTML code. |
The generated HTML code for displaying the captcha
todo |
---|
getTimeToSolve() : int
Get the time in seconds that it took to solve the captcha.
The time in seconds from when the code was created, to when it was solved
todo |
---|
setNamespace(string $namespace)
Set the namespace for the captcha being stored in the session or database.
Namespaces are useful when multiple captchas need to be displayed on a single page.
string | $namespace | Namespace value, String consisting of characters "a-zA-Z0-9_-" |
todo |
---|
outputAudioFile()
Generate an audible captcha in WAV format and send it to the browser with appropriate headers.
Example:
$img = new Securimage();
$img->outputAudioFile(); // outputs a wav file to the browser
exit;
todo |
---|
getCode(bool $array, bool $returnExisting) : array|string
Return the code from the session or database (if configured). If none exists or was found, an empty string is returned.
bool | $array | true to receive an array containing the code and properties, false to receive just the code. |
bool | $returnExisting | If true, and the class property code is set, it will be returned instead of getting the code from the session or database. |
Return is an array if $array = true, otherwise a string containing the code
todo |
---|
createCode()
This method generates a new captcha code.
Generates a random captcha code based on charset, math problem, or captcha from the wordlist and saves the value to the session and/or database.
todo |
---|
getRandomNoiseFile() : bool|string
Gets and returns the path to a random noise file from the audio noise directory.
false if a file could not be found, or a string containing the path to the file.
todo |
---|
frand() : float
Return a random float between 0 and 0.9999
Random float between 0 and 0.9999
todo |
---|
errorHandler(int $errno, string $errstr, string $errfile, int $errline, array $errcontext) : boolean
The error handling function used when outputting captcha image or audio.
This error handler helps determine if any errors raised would prevent captcha image or audio from displaying. If they have no effect on the output buffer or headers, true is returned so the script can continue processing.
See https://github.com/dapphp/securimage/issues/15
int | $errno | PHP error number |
string | $errstr | String description of the error |
string | $errfile | File error occurred in |
int | $errline | Line the error occurred on in file |
array | $errcontext | Additional context information |
true if the error was handled, false if PHP should handle the error
todo |
---|
doImage()
The main image drawing routing, responsible for constructing the entire image and serving it
todo |
---|
getBackgroundFromDirectory()
Scan the directory for a background image to use
todo |
---|
todo |
---|
todo |
---|
getAudibleCode() : string
Generates an audio captcha in WAV format
The audio representation of the captcha in Wav format
todo |
---|
readCodeFromFile(int $numWords) : string|array
Gets a captcha code from a file containing a list of words.
Seek to a random offset in the file and reads a block of data and returns a line from the file.
int | $numWords | Number of words (lines) to read from the file |
Returns a string if only one word is to be read, or an array of words
todo |
---|
generateCode() : string
Generates a random captcha code from the set character set
A randomly generated CAPTCHA code
todo |
---|
validate()
Validate a code supplied by the user
Checks the entered code against the value stored in the session and/or database (if configured). Handles case sensitivity. Also removes the code from session/database if the code was entered correctly to prevent re-use attack.
This function does not return a value.
todo |
---|
todo |
---|
openDatabase() : bool
Opens a connection to the configured database.
true if the database connection was successful, false if not
todo |
---|
getDsn() : string
Get the PDO DSN string for connecting to the database
If database specific options are not configured
The DSN for connecting to the database
todo |
---|
checkTablesExist() : boolean
Checks if the necessary database tables for storing captcha codes exist
If the table check failed for some reason
true if the database do exist, false if not
todo |
---|
createDatabaseTables() : boolean
Create the necessary databaes table for storing captcha codes.
Based on the database adapter used, the tables will created in the existing connection.
true if the tables were created, false if not
todo |
---|
getCodeFromDatabase() : string|array
Retrieves a stored code from the database for based on the captchaId or IP address if captcha ID not used.
Empty string if no code was found or has expired, otherwise returns array of code information.
todo |
---|
clearCodeFromDatabase()
Remove a stored code from the database based on captchaId or IP address.
todo |
---|
purgeOldCodesFromDatabase()
Deletes old (expired) codes from the database
todo |
---|
isCodeExpired(int $creation_time) : bool
Checks to see if the captcha code has expired and can no longer be used.
int | $creation_time | The Unix timestamp of when the captcha code was created |
true if the code is expired, false if it is still valid
todo |
---|
generateWAV(array $letters) : string
Generate a wav file given the $letters in the code
array | $letters | The letters making up the captcha |
The audio content in WAV format
todo |
---|
getSoxEffectChain(int $numEffects) : string
Get a random effect or chain of effects to apply to a segment of the audio file.
These effects should increase the randomness of the audio for a particular letter/number by modulating the signal. The SoX effects used are bend, chorus, overdrive, pitch, reverb, tempo, and tremolo.
For each effect selected, random parameters are supplied to the effect.
int | $numEffects | How many effects to chain together |
A string of valid SoX effects and their respective options.
todo |
---|
getSoxNoiseData(float $duration, int $numChannels, int $sampleRate, int $bitRate) : string
This function is not yet used.
Generate random background noise from sweeping oscillators
float | $duration | How long in seconds the generated sound will be |
int | $numChannels | Number of channels in output wav |
int | $sampleRate | Sample rate of output wav |
int | $bitRate | Bits per sample (8, 16, 24) |
Audio data in wav format
todo |
---|
audioError() : string
Return a wav file saying there was an error generating file
The binary audio contents
todo |
---|
canSendHeaders() : bool
Checks to see if headers can be sent and if any error has been output to the browser
true if it is safe to send headers, false if not
todo |
---|
initColor(string $color, \Securimage_Color $default)
Convert an html color code to a Securimage_Color
string | $color | |
\Securimage_Color | $default | The defalt color to use if $color is invalid |
todo |
---|