Код каптчи с сайта hight.fatal.ru![]() <?php
# # 2006-2008 (c) Hight | hight@inbox.ru # session_start(); header('Cache-Control: private, no-cache="set-cookie"'); header('Expires: 0'); header('Pragma: no-cache'); # Кол-во символов в строке $symbols_num = 6; # Цифры $numbers = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); # Буквы $letters = array('A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z'); # Генерация массива символов контрольной строки for($i = 0; $i < $symbols_num; $i++) { $true_false = rand(1, 2); # =) if(fmod($true_false, 2)) { $captcha_key_array[] = $numbers[rand(0, 9)]; } else { $captcha_key_array[] = $letters[rand(0, 51)]; } } $captcha_key = implode('', $captcha_key_array); $_SESSION['captcha'] = $captcha_key; # Берём щрифты $fonts_dir = opendir('fonts'); while(false !== ($module = readdir($fonts_dir))) { if($module != '.' and $module != '..') { $fonts_array[] = $module; } } $fonts_num = count($fonts_array); # Ширина-высота изображения $width = $symbols_num * 25; $height = 50; # Создание изображения $image = imagecreatetruecolor($width, $height); # рисуем фон $background = imagecolorallocate($image, rand(230, 255), rand(230, 255), rand(230, 255)); imagefill($image, 0, 0, $background); # рисуем "шахматную" доску $cube_side = rand(8, 12); # размер грани квадратика $q = 0; while($q <= $height / $cube_side) { $i = 0; while($i <= $width) { if(fmod($q, 2)) { $cube_side = rand(8, 12); # Размер стороны квадратика $color = imagecolorallocate($image, rand(150, 255), rand(150, 255), rand(150, 255)); imagefilledrectangle ($image, $i*2+$cube_side, $q*$cube_side, $i*2+$cube_side*2, $q*$cube_side+$cube_side, $color ); } else { $cube_side = rand(8, 12); # Размер стороны квадратика $color = imagecolorallocate($image, rand(150, 255), rand(150, 255), rand(150, 255)); imagefilledrectangle ($image, $i*2, $q*$cube_side, $i*2+$cube_side, $q*$cube_side+$cube_side, $color ); //imagesetpixel(, *2, *, ); //imagefilledarc (, *2, *, rand(8, 16), rand(5, 10), 0, 360, , IMG_ARC_PIE ); //imageellipse(, *2, *, 20, 10, ); } $i = $i + $cube_side; } $q++; } # рисуем строку $i = 10; foreach($captcha_key_array as $index => $value) { $x_position = rand(6, $height - 16); $str_color = imagecolorallocate($image, rand(50, 150), rand(50, 150), rand(50, 150)); $captcha_key_array = imagettftext($image, 25, rand(-30, 30), $i, rand(25, 45), $str_color, './fonts/'.$fonts_array[rand(0, $fonts_num-1)], $value); $i = $i + rand(15, 25) ; } # рисуем рамку $black = imagecolorallocate($image, 0, 0, 0); imageline($image, 0, 0, 0, $height, $black); # left imageline($image, $width - 1, 0, $width - 1, $height, $black); # right imageline($image, $width, 0, 0, 0, $black); # up imageline($image, $width, $height - 1, 0, $height - 1, $black); # down # Выводим изображение в браузер header('content-type: image/png'); imagepng($image); # Высвобождаем ресурсы imagedestroy($image); ?> |