仰望星辰工作室

better-staridc-MNBT

better-staridc-MNBT/ admin/code.php 1.2 KB · 73 行 原始文件
Z zfhsh first commit 1 天前
1<?php
2
3session_start();
4
5$image = imagecreatetruecolor(100, 30);
6
7$bgcolor = imagecolorallocate($image, 255, 255, 255);
8
9imagefill($image, 0, 0, $bgcolor);
10
11
12
13$captch_code = '';
14
15for ($i = 0; $i < 4; $i++) {
16
17 $fontsize = 6;
18
19 $fontcolor = imagecolorallocate($image, rand(0, 120), rand(0, 120), rand(0, 120));
20
21 $data = '1234567890';
22
23 $fontcontent = substr($data, rand(0, strlen($data) - 1), 1);
24
25 $captch_code .= $fontcontent;
26
27 $x = ($i * 100 / 4) + rand(5, 10);
28
29 $y = rand(5, 10);
30
31 imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);
32
33}
34
35//就生成的验证码保存到session
36
37$_SESSION['authcode'] = $captch_code;
38
39
40
41//在图片上增加点干扰元素
42
43for ($i = 0; $i < 200; $i++) {
44
45 $pointcolor = imagecolorallocate($image, rand(50, 200), rand(50, 200), rand(50, 200));
46
47 imagesetpixel($image, rand(1, 99), rand(1, 29), $pointcolor);
48
49}
50
51
52
53//在图片上增加线干扰元素
54
55for ($i = 0; $i < 3; $i++) {
56
57 $linecolor = imagecolorallocate($image, rand(80, 220), rand(80, 220), rand(80, 220));
58
59 imageline($image, rand(1, 99), rand(1, 29), rand(1, 99), rand(1, 29), $linecolor);
60
61}
62
63//设置头
64
65header('content-type:image/png');
66
67imagepng($image);
68
69imagedestroy($image);
70
71
72
73?>