-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcaptcha.php
More file actions
108 lines (71 loc) · 2.49 KB
/
Copy pathcaptcha.php
File metadata and controls
108 lines (71 loc) · 2.49 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/*=========================================================
// File: captcha.php
// Description: captcha page of EvalSMSI
// Created: 2009-01-01
// Licence: GPL-3.0-or-later
// Copyright 2009-2019 Michel Dubois
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
=========================================================*/
include("functions.php");
startSession();
if(isset($_SESSION['sess_captcha'])) {
unset($_SESSION['sess_captcha']);
}
$imgWidth = 85;
$imgHeight = 25;
function generateLines($image, $nbr) {
global $imgWidth, $imgHeight;
genSyslog(__FUNCTION__);
for($i=0; $i<=$nbr; $i++) {
$lineColor = imagecolorallocate($image, rand(0,255), rand(0,255), rand(0,255));
imageline($image, rand(1, $imgWidth-$imgHeight), rand(1, $imgHeight), rand(1, $imgWidth+$imgHeight), rand(1, $imgHeight), $lineColor);
}
}
function txtCaptcha($image) {
genSyslog(__FUNCTION__);
$captchaString = "ABCDEFGHJKLMNPQRSTUVWXYZ123456789";
$captchaString = str_shuffle($captchaString);
$_SESSION['sess_captcha'] = substr($captchaString, 0, 6);
$textColor = imagecolorallocate($image, 40, 45, 50);
imagestring($image, 5, 10, 4, $_SESSION['sess_captcha'], $textColor);
}
function numCaptcha($image) {
genSyslog(__FUNCTION__);
$captchaNumber = ["un", "deux", "trois", "quatre", "cinq"];
$val1 = rand(1, 5);
$val2 = rand(1, 5);
$_SESSION['sess_captcha'] = $val1 * $val2;
$captchaString = $captchaNumber[$val1-1].'*'.$captchaNumber[$val2-1].'=';
$textColor = imagecolorallocate($image, 40, 45, 50);
imagestring($image, 3, 0, 4, $captchaString, $textColor);
}
header('Content-Type: image/png');
$img = imagecreatetruecolor($imgWidth, $imgHeight);
$bg = imagecolorallocate($img, 0, 0, 0);
imagecolortransparent($img, $bg);
generateLines($img, 5);
switch ($_SESSION['captchaMode']) {
case 'txt':
txtCaptcha($img);
break;
case 'num':
numCaptcha($img);
break;
default:
numCaptcha($img);
break;
}
imagepng($img);
imagedestroy($img);
?>
?>