-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaptcha1.php
More file actions
125 lines (59 loc) · 2.13 KB
/
captcha1.php
File metadata and controls
125 lines (59 loc) · 2.13 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
session_start();
$width = 100;
$height = 38;
$length = 5;
$font = './arial.ttf';
$font_size = 12;
$bg_color = array(240, 240, 240);
$chars = 'ABCDEFGHKMNPQRSTUVWXYZ23456789';
if (extension_loaded('gd') == false)
{
die("The GD extension is required for CAPTCHA!");
}
if (function_exists('imagettftext') == false)
{
die("The function 'imagettftext' is required for CAPTCHA!");
}
$img = imagecreatetruecolor($width, $height);
$bkgr = imagecolorallocate($img, $bg_color[0], $bg_color[1], $bg_color[2]);
imagefilledrectangle($img, 0, 0, $width, $height, $bkgr);
$code = '';
for ($i = 0; $i < $length; $i++)
{
$code .= $chr = $chars[mt_rand(0, strlen($chars)-1)];
$r = rand(0, 192);
$g = rand(0, 192);
$b = rand(0, 192);
$color = imagecolorallocate($img, $r, $g, $b);
$shadow = imagecolorallocate($img, $r/3, $g/3, $b/3);
$angle = rand(-35, 35);
$x = 5+$i*(4/3*$font_size+2);
$y = rand(4/3*$font_size, $height-(4/3*$font_size)/2);
imagettftext($img, $font_size, $angle, $x+1, $y+3, $shadow, $font, $chr);
imagettftext($img, $font_size, $angle, $x, $y, $color, $font, $chr);
}
$amplitude = 5;
$period = 10;
$random_period = $period * rand(1, 3);
$sin = rand(0, 100);
for ($i=0; $i<$width; $i++)
{
imagecopy($img, $img, $i-1, sin($sin+$i/$random_period)*$amplitude, $i, 0, 1, $height);
}
$random_period = $period * rand(1, 2);
$sin = rand(0, 100);
for ($i=0; $i<$height; $i++)
{
imagecopy($img, $img, sin($sin+$i/$random_period)*$amplitude, $i-1, 0, $i, $width, 1);
}
$_SESSION['captcha'] = md5($code);
header("Content-type: image/png");
header("Expires: Tue, 28 Mar 2000 12:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
imagepng($img);
imagedestroy($img);
?>