-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaptcha.php
37 lines (27 loc) · 980 Bytes
/
captcha.php
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
26
27
28
29
30
31
32
33
34
35
36
37
<?php
$letters = 'ABCDEFGKIJKLMNOPQRSTUVWXYZ';
$caplen = 6;
$width = 120; $height = 40;
$font = 'fonts/comic.ttf';
$fontsize = 14;
header('Content-type: image/png');
$im = imagecreatetruecolor($width, $height);
imagesavealpha($im, true);
$bg = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $bg);
putenv( 'GDFONTPATH=' . realpath('.') );
$captcha = '';
for ($i = 0; $i < $caplen; $i++){
$captcha .= $letters[ rand(0, strlen($letters)-1) ];
$x = ($width - 20) / $caplen * $i + 10;
$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_start();
$_SESSION['capcha'] = $captcha;
imagepng($im);
imagedestroy($im);
?>