PHP 클래스 Securimage, PHP-Fusion

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.
저자: Drew Phillips ([email protected])
파일 보기 프로젝트 열기: php-fusion/PHP-Fusion 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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

공개 메소드들

메소드 설명
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

메소드 상세

Securimage() 공개 메소드

$securimage = new Securimage();
public Securimage ( )

addSignature() 공개 메소드

Print signature text on image
부터: 2.0
public addSignature ( )

allocateColors() 공개 메소드

Allocate all colors that will be used in the CAPTCHA image
부터: 2.0.1
public allocateColors ( )

check() 공개 메소드

$code = $_POST['code']; if ($securimage->check($code) == false) { die("Sorry, the code entered did not match."); } else { $valid = true; }
public check ( string $code ) : boolean
$code string The code the user entered
리턴 boolean true if the code was correct, false if not

checkCode() 공개 메소드

Check if the user entered code was correct
public checkCode ( ) : boolean
리턴 boolean

clearCodeFromDatabase() 공개 메소드

Delete a code from the database by ip address hash
부터: 2.0.1

createCode() 공개 메소드

Create a code and save to the session
부터: 1.0.1
public createCode ( )

distortedCopy() 공개 메소드

Warp text from temporary image onto final image.
Modified for securimage
부터: 2.0
저자: Han-Kwang Nienhuys modified
public distortedCopy ( )

doImage() 공개 메소드

Generate and output the image
public doImage ( )

drawLines() 공개 메소드

Draw random curvy lines over the image
Modified code from HKCaptcha
부터: 2.0
public drawLines ( )

drawWord() 공개 메소드

Draw the CAPTCHA code over the image
public drawWord ( )

frand() 공개 메소드

Generate random number less than 1
부터: 2.0
public frand ( ) : float
리턴 float

generateCode() 공개 메소드

Generate a code
public generateCode ( integer $len ) : string
$len integer The code length
리턴 string

generateMP3() 공개 메소드

Generate an mp3 file by concatenating individual files
부터: 1.0.4
public generateMP3 ( array $letters ) : string
$letters array Array of letters to build a file from
리턴 string MP3 file data

generateWAV() 공개 메소드

Generate a wav file by concatenating individual files
부터: 1.0.1
public generateWAV ( array $letters ) : string
$letters array Array of letters to build a file from
리턴 string WAV file data

getAudibleCode() 공개 메소드

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
부터: 1.0.1
public getAudibleCode ( $format = 'wav' ) : string
리턴 string WAV or MP3 data

getBackgroundFromDirectory() 공개 메소드

Return the full path to a random gif, jpg, or png from the background directory.
또한 보기: Securimage::$background_directory
public getBackgroundFromDirectory ( ) : mixed
리턴 mixed false if none found, string $path if found

getCode() 공개 메소드

Get the captcha code
부터: 1.0.1
public getCode ( ) : string
리턴 string

getCodeFromDatabase() 공개 메소드

Get stored captcha code from sqlite database based on ip address hash
부터: 2.0.1
public getCodeFromDatabase ( ) : string
리턴 string captcha code

getIPHash() 공개 메소드

Get hashed IP address of remote user
부터: 2.0.1
public getIPHash ( ) : string
리턴 string

isCodeExpired() 공개 메소드

Check a code to see if it is expired based on creation time
부터: 2.0.1
public isCodeExpired ( $creation_time ) : boolean
$creation_time unix timestamp of code creation time
리턴 boolean true if code has expired, false if not

openDatabase() 공개 메소드

Open SQLite database
부터: 2.0.1
public openDatabase ( ) : boolean
리턴 boolean true if database was opened successfully

output() 공개 메소드

Output image to the browser
public output ( )

outputAudioFile() 공개 메소드

Output audio file with HTTP headers to browser $sound = new Securimage(); $sound->audio_format = 'mp3'; $sound->outputAudioFile();
부터: 2.0
public outputAudioFile ( )

purgeOldCodesFromDatabase() 공개 메소드

Purge codes over a day old from database
부터: 2.0.1

readCodeFromFile() 공개 메소드

Reads a word list file to get a code
부터: 1.0.2
public readCodeFromFile ( ) : mixed
리턴 mixed false on failure, a word on success

saveCodeToDatabase() 공개 메소드

Save captcha code to sqlite database
부터: 2.0.1
public saveCodeToDatabase ( ) : boolean
리턴 boolean true if code was saved, false if not

saveData() 공개 메소드

Save the code in the session
public saveData ( )

scrambleAudioData() 공개 메소드

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.
부터: 2.0
public scrambleAudioData ( &$data, $format )
$data Sound data in mp3 of wav format

setAudioPath() 공개 메소드

Set the path to the audio directory.
부터: 1.0.4
public setAudioPath ( $audio_directory ) : boolean
리턴 boolean true if the directory exists and is readble, false if not

setBackground() 공개 메소드

Set the background of the CAPTCHA image
public setBackground ( )

show() 공개 메소드

show('bg.jpg');
public show ( string $background_image = "" )
$background_image string The path to an image to use as the background for the CAPTCHA

validate() 공개 메소드

Validate the code to the user code
public validate ( )

프로퍼티 상세

$audio_format 공개적으로 프로퍼티

Type of audio file to generate (mp3 or wav)
public string $audio_format
리턴 string

$audio_path 공개적으로 프로퍼티

Full path to the WAV files to use to make the audio files, include trailing /.
Name Files [A-Z0-9].wav
부터: 1.0.1
public string $audio_path
리턴 string

$background_directory 공개적으로 프로퍼티

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.
public string $background_directory
리턴 string

$bgimg 공개적으로 프로퍼티

The background image resource
public resource $bgimg
리턴 resource

$charset 공개적으로 프로퍼티

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.
public string $charset
리턴 string

$code 공개적으로 프로퍼티

The code generated by the script
public string $code
리턴 string

$code_entered 공개적으로 프로퍼티

The code that was entered by the user
public string $code_entered
리턴 string

$code_length 공개적으로 프로퍼티

The length of the code to generate.
public int $code_length
리턴 integer

$correct_code 공개적으로 프로퍼티

Whether or not the correct code was entered
public bool $correct_code
리턴 boolean

$draw_lines_over_text 공개적으로 프로퍼티

Draw the lines over the text.
If fales lines will be drawn before putting the text on the image.
public bool $draw_lines_over_text
리턴 boolean

$expiry_time 공개적으로 프로퍼티

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.
public int $expiry_time
리턴 integer

$gd_font_file 공개적으로 프로퍼티

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.
public mixed $gd_font_file
리턴 mixed

$gd_font_size 공개적으로 프로퍼티

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.
public int $gd_font_size
리턴 integer

$gdbgcolor 공개적으로 프로퍼티

Color resource for image background color
public int $gdbgcolor
리턴 integer

$gdlinecolor 공개적으로 프로퍼티

Color resource for image line color
public int $gdlinecolor
리턴 integer

$gdmulticolor 공개적으로 프로퍼티

Array of colors for multi colored codes
public array $gdmulticolor
리턴 array

$gdsignaturecolor 공개적으로 프로퍼티

Color resource for image signature color
public int $gdsignaturecolor
리턴 integer

$gdtextcolor 공개적으로 프로퍼티

Color resource for image font color
public int $gdtextcolor
리턴 integer

$im 공개적으로 프로퍼티

The gd image resource.
public resource $im
리턴 resource

$image_bg_color 공개적으로 프로퍼티

The background color for the image as a Securimage_Color.
public Securimage_Color $image_bg_color
리턴 Securimage_Color

$image_height 공개적으로 프로퍼티

The desired width of the CAPTCHA image.
public int $image_height
리턴 integer

$image_signature 공개적으로 프로퍼티

Text to write at the bottom corner of captcha image
부터: 2.0
public $image_signature

$image_type 공개적으로 프로퍼티

The image format for output.
Valid options: SI_IMAGE_PNG, SI_IMAGE_JPG, SI_IMAGE_GIF
public int $image_type
리턴 integer

$image_width 공개적으로 프로퍼티

The desired width of the CAPTCHA image.
public int $image_width
리턴 integer

$iscale 공개적으로 프로퍼티

Internal scale factor for anti-alias @hkcaptcha
부터: 2.0
public int $iscale
리턴 integer

$line_color 공개적으로 프로퍼티

Color of lines drawn over text
public string $line_color
리턴 string

$multi_text_color 공개적으로 프로퍼티

Array of Securimage_Colors which will be randomly selected for each letter.
public array $multi_text_color
리턴 array

$num_lines 공개적으로 프로퍼티

Draw vertical and horizontal lines on the image.
또한 보기: Securimage::$line_color
또한 보기: Securimage::$draw_lines_over_text
public bool $num_lines
리턴 boolean

$perturbation 공개적으로 프로퍼티

How much to distort image, higher = more distortion.
Distortion is only available when using TTF fonts.
public float $perturbation
리턴 float

$session_name 공개적으로 프로퍼티

The session name to use if not the default. Blank for none
또한 보기: http://php.net/session_name
부터: 2.0
public string $session_name
리턴 string

$signature_color 공개적으로 프로퍼티

Color to use for writing signature text
부터: 2.0
public Securimage_Color $signature_color
리턴 Securimage_Color

$sqlite_database 공개적으로 프로퍼티

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.
public string $sqlite_database
리턴 string

$sqlite_handle 공개적으로 프로퍼티

Handle to SQLite database
public resource $sqlite_handle
리턴 resource

$text_angle_maximum 공개적으로 프로퍼티

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.
public int $text_angle_maximum
리턴 integer

$text_angle_minimum 공개적으로 프로퍼티

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
public int $text_angle_minimum
리턴 integer

$text_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.
또한 보기: Securimage::$use_multi_text
public Securimage_Color $text_color
리턴 Securimage_Color

$text_transparency_percentage 공개적으로 프로퍼티

The percentage of transparency, 0 to 100.
A value of 0 is completely opaque, 100 is completely transparent (invisble)
또한 보기: Securimage::$use_transparent_text
public int $text_transparency_percentage
리턴 integer

$text_x_start 공개적으로 프로퍼티

The X-Position on the image where letter drawing will begin.
This value is in pixels from the left side of the image.
사용 중단: 2.0
public int $text_x_start
리턴 integer

$tmpimg 공개적으로 프로퍼티

Temporary image for rendering
public resource $tmpimg
리턴 resource

$ttf_file 공개적으로 프로퍼티

The path to the TTF font file to load.
public string $ttf_file
리턴 string

$use_gd_font 공개적으로 프로퍼티

Use a gd font instead of TTF
public $use_gd_font

$use_multi_text 공개적으로 프로퍼티

Set to true to use multiple colors for each character.
또한 보기: Securimage::$multi_text_color
public bool $use_multi_text
리턴 boolean

$use_sqlite_db 공개적으로 프로퍼티

Use an SQLite database for storing codes as a backup to sessions.
Note: Sessions will still be used
public $use_sqlite_db

$use_transparent_text 공개적으로 프로퍼티

Set to true to make the characters appear transparent.
또한 보기: Securimage::$text_transparency_percentage
public bool $use_transparent_text
리턴 boolean

$use_wordlist 공개적으로 프로퍼티

Use wordlist of not
public $use_wordlist

$wordlist_file 공개적으로 프로퍼티

Create codes using this word list
public $wordlist_file