Система защиты от автоматических регистраций (проверка картинкой)

kukuikar

Новичок
Система защиты от автоматических регистраций (проверка картинкой)

Привет всем.
Надыбал в сети следующий код.
PHP:
<?php 
//session_start(); 
function image_check($len) 
{ 
// Set the enviroment variable for GD 
//putenv('GDFONTPATH=' . realpath('.')); 

// Name the font to be used (note the lack of the .ttf extension) 
//$font = 'comic.ttf'; 

      
      
    define('FONT',"comic.ttf"); 
    define('SIZE_X',150); 
    define('SIZE_Y',25); 
    define('STEP',10); 
          
    # Создаем текст для картинки (функци вызывается с параметром $len=длине текста 
    $ranges = array 
    ( 
      1 => array(48, 57)  // 0-9 (numeral) 
        //2 => array(97, 122), // a-z (lowercase) 
        //3 => array(65, 90),  // A-Z (uppercase) 
          
    ); 
    $passw = ""; 
    for ($i=0; $i<$len; $i++) 
      { 
          $r = mt_rand(1,count($ranges)); 
          $passw .= chr (mt_rand($ranges[$r][0], $ranges[$r][1])); 
      } 

    #Запииваем это значение в сессию 
    $_SESSION['image_check_text'] = $passw; 
    //rand(1000000,9999999); - можно и так 

    $im = @ImageCreate(SIZE_X, SIZE_Y) or die ("Cannot Initialize new GD image stream"); 


    $background_color = ImageColorAllocate ($im, 255, 255, 255); 
    $text_color = ImageColorAllocate($im, 0, 0, 0); 
    $fon_color = ImageColorAllocate($im, 255, 150, 0); 

    #Рисуем кучу рандомных линий чтобы злобный бот не распознал текст 
    ImageSetThickness($im, 1); 
    ImageRectangle($im,0,0,SIZE_X-1,SIZE_Y-1,$text_color); 
    for($j=-2; $j<imagesx($im)/STEP+1; $j++){ 
        $last=0; 
        for($i=-2; $i<imagesy($im)/STEP+1; $i++) 
        { 
            $last = STEP*$i+rand(STEP/1.4,STEP*1.4); 
            $cur_points_y[] = $last; 
            $cur_points_x[] = rand($j*STEP+STEP/1.4,$j*STEP+STEP*1.4); 
        } 
        $cur_points_y[] = SIZE_Y; 
        $cur_points_x[] = rand($j*STEP+STEP/1.4,$j*STEP+STEP*1.4); 
        for($i=1; $i<5; $i++) 
        { 
            ImageLine($im,$prev_points_x[$i], $prev_points_y[$i], $cur_points_x[$i], $cur_points_y[$i], $fon_color); 
            ImageLine($im,$prev_points_x[$i-1], $prev_points_y[$i-1], $cur_points_x[$i], $cur_points_y[$i], $fon_color); 
            ImageLine($im,$prev_points_x[$i], $prev_points_y[$i], $cur_points_x[$i-1], $cur_points_y[$i-1], $fon_color); 
        } 
        unset($prev_points_x); 
        unset($prev_points_y); 
        $prev_points_x = $cur_points_x; 
        $prev_points_y = $cur_points_y; 
        unset($cur_points_x); 
        unset($cur_points_y); 
    } 
      
    $num = (string)$_SESSION['image_check_text']; 
      
    #Рисуем текст. Извращаемся как можем. 
    for($i = 0; $i < strlen($num); $i++) 
    { 
        $cipher = substr($num, $i, 1); 
        $psize = rand(imagesy($im)-8,imagesy($im)-3); 
        $angle = rand(0,60)-5; 
        $sizes = ImageTTFBBox($psize, $angle, FONT, $cipher); 
        $width = $sizes[2]-$sizes[0]; 
        $height = $sizes[1]-$sizes[7]; 
        $dh = (SIZE_Y-2-$height)/2; 
        $px = (imagesx($im)/strlen($num))*$i+(imagesx($im)/strlen($num)-$width)/2; 
        $py = ($height+$dh+1)+rand(-$dh, $dh); 
        ImageTTFText ($im, $psize, $angle, $px, $py, $text_color, FONT, $cipher); 
    } 
    imagerectangle($im,0,0,SIZE_X,SIZE_Y,$text_color); 
      
header("Accept-ranges: bytes"); 
header("Content-type: image/png"); 

ImagePng($im); 
} 
?>
Встраиваю в страницу так:
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Untitled Document</title> 
</head> 
<?php 
session_start(); 
require_once("./icheck.php"); 

image_check(6); 

?> 

<form action="<?=$_SERVER['PHP_SELF'] ?>" enctype="application/x-www-form-urlencoded" method="post"> 
<input type="text" name="num" value=""> 
<input type="hidden" name="check" value="1"> 
<input type="submit"> 
</form> 
<?php 

if (isset($check)) 
   { 
   if ($num == $_SESSION['image_check_text']) 
      echo "Номер верен"; 
   else 
      echo "Номер неверен"; 
   } 
?>     

<body> 
</body> 
</html>
В итоге получаю следующую картину http://www.ler-bochka.ru/ich.php

Т.е. вместо каринки - какаю-то белиберда...
Если не встраивить , то картинка появляется...

Выввихнул мозг. Помогите разобраться....
 
Сверху