captcha gd
yazım: 24 Mart 09 10:29 / güncelleme: 25 Mart 09 20:26
php gd ile captcha
php gd ile captcha örneği
session_start(); $charCount = 6; $width = 100; $height = 35; $im=@imagecreate($width, $height); $width = $width - 10; if($width/$charCount > $height) { $fontSize = $height; } else { $fontSize = $width/$charCount >> 0; $padding = $height - $fontSize; } imagecolorallocate($im, 0, 0, 0); $white = imagecolorallocate($im, 255, 255, 255); $color = imagecolorallocate($im,rand(150,255),rand(150,255),rand(150,255)); imageline($im, rand(3,$width), rand(3,$height), rand(3,$width), rand(3,$height), imagecolorallocate($im, 150, 150, 150)); $possible = '23456789bcdfghjkmnpqrstvwxyz'; $codeText = ''; $i = 0; $left = 5; $font = 'lib/captcha/captcha.ttf'; while ($i < $charCount) { $codeColor=imagecolorallocate($im,255-rand(100,255),255-rand(100,255),255-rand(100,255)); $codeText .= $codeChar = (rand(0,10)>5)?strtoupper(substr($possible, rand(0, strlen($possible)-1), 1)):(substr($possible, rand(0, strlen($possible)-1), 1)); $size = $height * rand(5,7)*.1; imagettftext($im, $fontSize, rand(-21,21), $left, ($height+$padding)*.5, $codeColor, $font, $codeChar); $left += $fontSize; $i++; } header("Content-type: image/jpeg"); header("Content-Disposition:inline ; filename=secure.jpg"); imagejpeg($im); imagedestroy($im); $_SESSION['captcha'] = $codeText;






