Thread: class_tscaphta
View Single Post
  #2  
Old 23rd August 2011, 20:41
zero zero is offline
Senior Member
 
Join Date: Jun 2009
Finland
Posts: 16
Default
PHP Code:
<?php


class tscaptcha
{

    public function 
tscaptcha$width$height$characters )
    {
        
$font dirname__FILE__ )."/captcha_fonts/monofont.ttf";
        
$code generateCode$characters );
        
$font_size $height 0.75;
        if ( !( 
$image = @imagecreate( @$width, @$height ) ) )
        {
            exit( 
"Cannot initialize new GD image stream" );
        }
        
$background_color imagecolorallocate$image255255255 );
        
$text_color imagecolorallocate$image2040100 );
        
$noise_color imagecolorallocate$image100120180 );
        
$i 0;
        while ( 
$i $width $height )
        {
            
imagefilledellipse$imagemt_rand0$width ), mt_rand0$height ), 11$noise_color );
            ++
$i;
        }
        
$i 0;
        while ( 
$i $width $height 150 )
        {
            
imageline$imagemt_rand0$width ), mt_rand0$height ), mt_rand0$width ), mt_rand0$height ), $noise_color );
            ++
$i;
        }
        if ( !( 
$textbox imagettfbbox$font_size0$font$code ) ) )
        {
            exit( 
"Error in imagettfbbox function" );
        }
        
$x = ( $width $textbox[4] ) / 2;
        
$y = ( $height $textbox[5] ) / 2;
        if ( !
imagettftext$image$font_size0$x$y$text_color$font$code ) )
        {
            exit( 
"Error in imagettftext function" );
        }
        
header"Expires: Mon, 01 Jan 1990 00:00:00 GMT" );
        
header"Last-Modified: ".gmdate"D, d M Y H:i:s" )." GMT" );
        
header"Cache-Control: no-store, no-cache, must-revalidate" );
        
header"Cache-Control: post-check=0, pre-check=0"false );
        
header"Pragma: no-cache" );
        
header"Content-Type: image/jpeg" );
        
imagejpeg$image );
        
imagedestroy$image );
        
$_SESSION['security_code'] = $code;
    }

    public function 
generatecode$characters )
    {
        unset( 
$_SESSION['security_code'] );
        
$possible "abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ";
        
$code "";
        
$i 0;
        while ( 
$i $characters )
        {
            
$code .= substr$possiblemt_rand0strlen$possible ) - ), );
            ++
$i;
        }
        return 
$code;
    }

}

class 
tscaptcha2 extends tscaptcha
{

    public function 
tscaptcha2$width$height$characters )
    {
        
$code generateCode$characters );
        if ( !( 
$im = @imagecreate( @$width, @$height ) ) )
        {
            exit( 
"Cannot Initialize new GD image stream" );
        }
        
$background_color imagecolorallocate$im00);
        
$text_color imagecolorallocate$im2331491 );
        
$font_size $height 0.75;
        
$bottom $height 2;
        
$center $width 2;
        
imagestring$im$font_size$center$bottom$code$text_color );
        
header"Expires: Mon, 01 Jan 1990 00:00:00 GMT" );
        
header"Last-Modified: ".gmdate"D, d M Y H:i:s" )." GMT" );
        
header"Cache-Control: no-store, no-cache, must-revalidate" );
        
header"Cache-Control: post-check=0, pre-check=0"false );
        
header"Pragma: no-cache" );
        
header"Content-Type: image/png" );
        
imagepng$im );
        
imagedestroy$im );
    }

}

function 
gd_version( )
{
    static 
$gd_version;
    if ( 
$gd_version )
    {
        return 
$gd_version;
    }
    if ( !
extension_loaded"gd" ) )
    {
        exit( );
    }
    
ob_start( );
    
phpinfo);
    
$info ob_get_contents( );
    
ob_end_clean( );
    
$info stristr$info"gd version" );
    
preg_match"/\\d/"$info$gd );
    
$gd_version $gd[0];
    return 
$gd_version;
}

@
error_reporting( @E_ALL & @~E_NOTICE );
@
ini_set"error_reporting", @E_ALL & @~E_NOTICE );
@
ini_set"display_errors""0" );
@
ini_set"session.gc_maxlifetime""18000" );
@
session_cache_expire1440 );
@
set_time_limit);
@
set_magic_quotes_runtime);
@
ini_set"magic_quotes_sybase");
@
session_name"TSSE_Session" );
@
session_start( );
define"CTSC_VERSION""0.1 by xam" );
$width = isset( $_GET['width'] ) ? intval$_GET['width'] ) : "200";
$height = isset( $_GET['height'] ) ? intval$_GET['height'] ) : "60";
$characters = isset( $_GET['characters'] ) && $_GET['characters'] ? intval$_GET['characters'] ) : "6";
$gd_version gd_version( );
if ( 
function_exists"imagettftext" ) && function_exists"imagettfbbox" ) && <= gd_version( ) && !isset( $_GET['type'] ) )
{
    
$Var_1728->TsCaptcha$width$height$characters );
    
$captcha $Var_1728;
}
else
{
    
$Var_1896->TsCaptcha2$width$height$characters );
    
$captcha $Var_1896;
}
?>
Reply With Quote
The Following User Says Thank You to zero For This Useful Post:
smoky28 (23rd August 2011)