-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaptcha.php
More file actions
31 lines (25 loc) · 971 Bytes
/
captcha.php
File metadata and controls
31 lines (25 loc) · 971 Bytes
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
<?php
$image = @imagecreatetruecolor(120, 30);
// set background color and set drawing colors
$background = imagecolorallocate($image, 250, 250, 250);
imagefill($image, 0, 0, $background);
$linecolor = imagecolorallocate($image, 23, 88, 211);
$textcolor = imagecolorallocate($image, 39, 36, 36);
// draw random lines on canvas
for ($i=0; $i < 4; $i++) {
imagesetthickness($image, rand(1, 2));
imageline($image, 0, rand(0, 30), 120, rand(0, 30), $linecolor);
}
session_start();
// add random digits to canvas
$digit = '';
for ($x = 15; $x <= 95; $x += 20) {
$digit .= ($num = rand(0, 9));
imagechar($image, rand(3, 5), $x, rand(2, 14), $num, $textcolor);
}
// set digit in session to be able to check if correct input was given by user
$_SESSION['digit'] = $digit;
// display image and destroy so you always create new captcha
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);