ultimix
captcha_1_0_0 Class Reference

Public Member Functions

 __construct ()
 prepare_image ()
 get_font_settings ($Image)
 create_captcha (&$Options)
 get_sesion_name (&$Options)
 validate_captcha ($InputCaptcha, $Options)
 output_image (&$Image)
 view ($Options)

Data Fields

 $Security = false
 $Chars = false

Detailed Description

Captcha.

Author
Dodonov A.A.

Definition at line 34 of file captcha.php.

Constructor & Destructor Documentation

__construct ( )

Constructor.

Author
Dodonov A.A.

Definition at line 70 of file captcha.php.

{
try
{
$this->Security = get_package( 'security' , 'last' , __FILE__ );
$this->Chars = '0123456789';
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

Member Function Documentation

create_captcha ( $Options)

Function creates captcha.

Parameters
$Options- Settings.
Returns
array( $Image , $Str ).
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 184 of file captcha.php.

{
try
{
$Image = $this->prepare_image();
$Str = "";
list( $FontFile , $Align , $Start , $Interval , $Color , $Count ) = $this->get_font_settings( $Image );
for( $i = 0 ; $i < 5 ; $i++ )
{
$Char = $this->Chars[ rand( 0 , $Count - 1 ) ];
$FontSize = rand( 15 , 25 );
$CharAngle = rand( -10 , 10 );
imagettftext(
$Image , $FontSize , $CharAngle , $Start , $Align , $Color , $FontFile , $Char
);
$Start += $Interval;
$Str .= $Char;
}
return( array( $Image , $Str ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_font_settings (   $Image)

Function returns text parameters.

Parameters
$Image- Image.
Returns
array( $FontFile , $CharAlign , $Start , $Interval , $Color , $NumChars ).
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 143 of file captcha.php.

{
try
{
$FontFile = dirname( __FILE__ ).'/res/font/albonic.ttf'; /* путь к файлу относительно w3captcha.php */
$CharAlign = 22; /* выравнивание символа по-вертикали */
$Start = 5; /* позиция первого символа по-горизонтали */
$Interval = 16; /* интервал между началами символов */
$Color = imagecolorallocate( $Image , 255 , 0 , 0 ); /* rbg-цвет тени */
$NumChars = strlen( $this->Chars );
return( array( $FontFile , $CharAlign , $Start , $Interval , $Color , $NumChars ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_sesion_name ( $Options)

Function returns captcha name.

Parameters
$Options- Settings.
Returns
Captcha name.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 235 of file captcha.php.

{
try
{
$SessionName = 'captcha';
if( $Options->get_setting( 'captcha_name' , false ) !== false )
{
if( $Options->get_setting( 'captcha_name' ) == 'auto' )
{
$SessionName = $Options->get_setting( 'captcha_name' );
}
else
{
$SessionName = md5(
$this->Security->get_srv( 'SCRIPT_NAME' , 'string' ).
$this->Security->get_srv( 'QUERY_STRING' , 'string' )
);
}
}
return( $SessionName );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
output_image ( $Image)

Function draws capcha.

Parameters
$Image- Captcha.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 320 of file captcha.php.

{
try
{
if( function_exists( "imagepng" ) )
{
header( "Content-type: image/png" );
imagepng( $Image );
}
elseif( function_exists( "imagegif" ) )
{
header( "Content-type: image/gif" );
imagegif( $Image );
}
elseif( function_exists( "imagejpeg" ) )
{
header( "Content-type: image/jpeg" );
imagejpeg( $Image );
}
imagedestroy( $Image );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
prepare_image ( )

Function prepares image.

Returns
Image.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 101 of file captcha.php.

{
try
{
$Width = 100; /* ширина картинки */
$Height = 30; /* высота картинки */
$Image = imagecreatetruecolor( $Width , $Height );
$BackgroundColor = imagecolorallocate( $Image , 255 , 255 , 255 ); /* rbg-цвет фона */
imagefill( $Image , 0 , 0 , $BackgroundColor);
return( $Image );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
validate_captcha (   $InputCaptcha,
  $Options 
)

Function validates captcha.

Parameters
$InputCaptcha- Input value.
$Options- Execution options.
Returns
true if the captcha was inputed correctly.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 290 of file captcha.php.

{
try
{
return( @$_SESSION[ $this->get_sesion_name( $Options ) ] == $InputCaptcha );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
view (   $Options)

Function draws captcha.

Parameters
$Options- Settings.
Returns
HTML code of the form.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 370 of file captcha.php.

{
try
{
@session_start();
list( $Image , $Str ) = $this->create_captcha( $Options );
$_SESSION[ $this->get_sesion_name( $Options ) ] = $Str;
$this->output_image( $Image );
return( '' );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

Field Documentation

$Chars = false

Chars for captcha.

Author
Dodonov A.A.

Definition at line 58 of file captcha.php.

$Security = false

Cached objects.

Author
Dodonov A.A.

Definition at line 46 of file captcha.php.


The documentation for this class was generated from the following file: