php header Content-type image png session_start letters ABCDEFGKIJKLMN

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
header('Content-type: image/png');
session_start();
$letters = 'ABCDEFGKIJKLMNOPQRSTUVWXYZ';
$caplen = 5;
$captcha = '';
$width = 115; $height = 25;
$font = '../bido/captcha.ttf';
$fontsize = 9;
$im = imagecreatetruecolor($width + 9, $height);
$bg = imagecolorallocate($im, 213, 213, 213);
imagefill($im, 0, 0, $bg);
for ($i = 0; $i < $caplen; $i++)
{
$captcha .= $letters[ rand(0, strlen($letters)-1) ];
$x = ($width) / $caplen * $i + 6;
$x = rand($x, $x+4);
$y = $height - ( ($height - $fontsize) / 2 );
$curcolor = imagecolorallocate( $im, rand(0, 100), rand(0, 100), rand(0, 100) );
$angle = rand(-25, 25);
imagettftext($im, $fontsize, $angle, $x, $y, $curcolor, $font, $captcha[$i]);
}
$_SESSION['captcha'] = $captcha;
imagepng($im);
?>