php Class Controller_captcha Extends Controller_Base function index ra

 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
38
39
40
41
42
43
44
45
46
47
48
<?php
Class Controller_captcha Extends Controller_Base {
function index() {
$random = rand(1000, 9999);
$_SESSION['captcha'] = md5(md5("7788") . $random);
$font_count = glob(SITE_PATH . '/core/fonts/*.ttf');
$font = $font_count[mt_rand(0, count($font_count)-1)];
$img = imagecreatetruecolor(100, 50);
//колорит
$textColor = imagecolorallocate($img, 21,57,132);
$backgroundColor = imagecolorallocate($img, 219, 219, 219);
imagefilledrectangle($img, 0, 0, 100, 50, $backgroundColor);
//текст
$angle_rand = mt_rand(0, 10);
$x_rand = mt_rand(10, 15);
$y_rand = mt_rand(40, 45);
imagettftext($img, 25, $angle_rand, $x_rand, $y_rand, $textColor, $font, $random);
$line_color = imagecolorallocate($img, 21,57,132);
for($i=0; $i<10; $i++) {
imageline($img, 0, rand() % 50, 200, rand() % 70, $line_color);
}
$pixel_color = imagecolorallocate($img, 21,57,132);
for($i=0; $i<500; $i++) {
imagesetpixel($img, rand() % 200, rand() % 70, $pixel_color);
imagesetpixel($img, rand() % 200, rand() % 70, $pixel_color);
}
header ("Content-type: image/gif");
header('Cache-control: no-cache');
imagegif($img);
imagedestroy($img);
}
}