Kodlar
session_start();
class CaptchaSecurityImages {
var $font = 'captcha_font.ttf';
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = 'abcdefghsytrk123456789';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurityImages($width='80',$height='20',$characters='5') {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.70;
$image = @imagecreate($width, $height) or die('Yeni GD Goruntu akisi baslatilamiyor!');
/* set the colours */
$background_color = imagecolorallocate($image, 0, 0, 0);
$text_color = imagecolorallocate($image, 255, 255, 255);
$noise_color = imagecolorallocate($image, 100, 120, 180);
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('"imagettfbbox" Fonksiyonu hatasi!');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('"imagettftext" Fonksiyonu hatasi!');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
$_SESSION['guvenlik_kodu'] = $code;
session_register("guvenlik_kodu");
}
}
$width = isset($_GET['width']) ? $_GET['width'] : '100';
$height = isset($_GET['height']) ? $_GET['height'] : '20';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '5';
$captcha = new CaptchaSecurityImages($width,$height,$characters);
$_SESSION['guvenlik_kodu'] = $code;
session_register("guvenlik_kodu");
?>