?,./\|{}[]':;~`ABCDEFGHJKLMNPQRSTWXYZabcdefghjkmnpqrstwxyz23456789"; $code = ""; // generate code random letters for($i = 0; $i<$passlen; $i++) { $code = $code . substr($possiblechars,rand(0,strlen($possiblechars)-1),1); } // generate noise for($i = 0; $i<($passlen*2); $i++) { $noise = $noise . substr($noisepossiblechars,rand(0,strlen($noisepossiblechars)-1),1); } // generate more noise for($i = 0; $i<($passlen*2); $i++) { $noise2 = $noise2 . substr($noisepossiblechars,rand(0,strlen($noisepossiblechars)-1),1); } // lowercase > hash > store in session-variable $_SESSION['code'] = strtolower($code); //$image = imageCreateTrueColor($width, $height); // make a gradient for ($i = 0; $i < $width ; $i++) { $j = ($i+$gradient_red)*180/($width+$gradient_red)+75; $k = ($i+$gradient_green)*180/($width+$gradient_green)+75; $l = ($i+$gradient_blue)*180/($width+$gradient_blue)+75; //$color = imagecolorallocate($image, $i*180/$width+75,$i*180/$width+75, $i*180/$width+75); $color = imagecolorallocate($im, $j, $k, $l); imageline($im, $i, 0, $i, $height, $color); } // print out noise for($i=0; $i<$passlen; $i++) { $font = rand(3,5); imagestring($im, $font, $width/$passlen*$i+rand(4,30), $height/rand(1,8)-rand(imagefontheight($font)/rand(1,8), imagefontheight(rand(1,5))), substr($noise,$i,1), $lightgrey); $ttfont = '/fonts/captcha3.ttf'; $size = rand(8,21); $angle = rand(-30,30); $text_box = rand($size,$size+24); $text_separation = $width/$passlen*$i+rand(1,15); imagettftext($im, $size, $angle, $text_separation ,$text_box, $lightgrey, $ttfont, substr($noise,$i,1)); } // print out noise2 for($i=0; $i<$passlen; $i++) { $ttfont = '/fonts/captcha.ttf'; $size = rand(8,21); $angle = rand(-30,30); $text_box = rand($size,$size+24); $text_separation = $width/$passlen*$i+rand(3,20); imagettftext($im, $size, $angle, $text_separation ,$text_box, $lightestgrey, $ttfont, substr($noise2,$i,1)); } // print out the letters for($i=0; $i<$passlen; $i++) { $ttfont = '/fonts/captcha2.ttf'; $size = rand(14,21); $angle = rand(-30,30); $text_box = rand($size,$size+12); $text_separation = $width/$passlen*$i+rand(4,7); // imagestring($im, $font, $width/$passlen*$i+rand(4,7), // $height/2-rand(imagefontheight($font)/2, imagefontheight($font)), // substr($code,$i,1), $textcolor); imagettftext($im, $size, $angle, $text_separation+1 ,$text_box+1, $grey, $ttfont, substr($code,$i,1)); imagettftext($im, $size, $angle, $text_separation ,$text_box, $black, $ttfont, substr($code,$i,1)); } // draw border $bordercolor = imagecolorallocate($im, 171, 173, 179); imagerectangle($im,0,0,$width-1,$height-1,$bordercolor); // fix headers to avoid caching header("Expires: Wed, 1 Jan 1997 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/gif'); // set content-type // Using imagepng() results in clearer text compared with imagejpeg() or imageGIF() // output the image imageGIF($im); imagedestroy($im); ?>