captcha.php
Code (php)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<!-- TITLE OF THE SITE -->
<title> Faso.comulu.com | Captcha sum </title>
<!-- MAKE THE SITE BEAUTIFULL -->
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Aldrich">
<?php
/****************************************
# Make two random number to count *
# (+ or -). And change in some cases *
# the number into letters to make it *
# for spammers harder to crack (almost *
# impossible because spambots can't *
# read) *
****************************************/
/****************************************
# Set an error, so we can display them *
****************************************/
$error = '';
/****************************************
# Make a random captcha image, call the *
# images like this: captcha1, captcha2 *
****************************************/
$image = 'images/captcha'.rand(1,8).'.jpg';
/****************************************
# Create two random numbers to decide *
# if we make a plus or min exercise *
****************************************/
$plusmin = rand(1,2);
/****************************************
# Make some random numbers, number1 is *
# between 10 and twenty and the second *
# one between 1 and 9 because PHP can't *
# count 0 or -0 *
****************************************/
$number1 = rand(10,20);
$number2 = rand(1,9);
/****************************************
# Make the numbers change into letters *
# (three,seven,nine,twelve,fifteen, *
# seventeen,nineteen aren't changing) *
****************************************/
$replace = array('1' => 'one', '2' => 'two', '4' => 'four', '5' => 'five', '6' => 'six', '8' => 'eight', '10' => 'ten', '11' => 'eleven', '13' => 'thirteen', '14' => 'fourteen', '16' => 'sixteen', '18' => 'eighteen', '20' => 'twenty');
/****************************************
# Check if the random number is in the *
# array and replace it with the letters *
# variation *
****************************************/
if(array_key_exists($number1, $replace)) {
$display1 = $replace[$number1]; }
else {
$display1 = $number1; }
/****************************************
# Do the same as above, but now with *
# number two *
****************************************/
if(array_key_exists($number2, $replace)) {
$display2 = $replace[$number2]; }
else {
$display2 = $number2; }
/****************************************
# Now go back to the plus or min case *
# and display the good one, if it is 1, *
# the sum is + else it is - *
****************************************/
if($plusmin == 1) {
$display = $display1.' + '.$display2;
$sumcheck = $number1 + $number2; }
else {
$display = $display1.' - '.$display2;
$sumcheck = $number1 - $number2; }
/****************************************
# If the submitter wants that we check *
# the captcha sum. *
****************************************/
if(isset($_POST['check_sum'])) {
/****************************************
# Trim the answer and set it as *
# variable $answer *
****************************************/
$answer = trim($_POST['sum_answer']);
/****************************************
# Rewrite the sum if the answer isn't *
# numeric (only try it) *
****************************************/
if(!is_numeric($answer)) {
/****************************************
# Change it now *
****************************************/
$replace = array('one' => '1', 'two' => '2', 'three' => '3', 'four' => '4', 'five' => '5', 'six' => '6', 'seven' => '7', 'eight' => '8', 'nine' => '9', 'ten' => '10', 'eleven' => '11', 'twelve' => '12', 'thirteen' => '13', 'fourteen' => '14', 'fifteen' => '15', 'sixteen' => '16', 'seventeen' => '17', 'eighteen' => '18', 'nineteen' => '19', 'twenty' => '20', 'twenty-one' => '21', 'twenty-two' => '22', 'twenty-three' => '23', 'twenty-four', '24', 'twenty-five' => '25', 'twenty-six' => '26', 'twenty-seven' => '27', 'twenty-eight' => '28', 'twenty-nine' => '29');
/****************************************
# If the answer is in the array above, *
# change it into numbers *
****************************************/
if(array_key_exists($answer, $replace)) {
$answer = $replace[$answer]; } }
/****************************************
# Now we tried to change the number and *
# everything like that, so we can check *
# the inserted answer *
****************************************/
if($_SESSION['sum'] == $answer) {
$error = '<div class="error">Your answer is correct!</div>'; }
else {
$error = '<div class="error">Your answer isn\'t correct!</div>'; } }
/****************************************
# Unset the session at the end of the *
# code and set a new one *
****************************************/
unset($_SESSION['sum']);
$_SESSION['sum'] = $sumcheck;
?>
</head>
<body>
<div class="wrapper">
Captcha Sum
</div>
<div class="container">
<!-- ERROR -->
<?php echo $bError; ?>
<!-- CAPTCHA IMAGE -->
<div class="captcha_background">
<img src="<?php echo $aImage; ?>" />
</div>
<!-- THE SUM -->
<div class="captcha_sum">
<?php echo $aDisplay; ?>
</div>
<!-- START THE FORM -->
<form action="" method="POST">
<!-- THE ANSWER BOX -->
<div class="answer_sum">
<input type="text" name="sum_answer" value="Insert answer" onBlur="if(this.value.length == 0) this.value='Insert answer';" onClick="if(this.value == 'Insert answer') this.value='';" />
</div>
<!-- ANSWER BUTTON -->
<div class="anwer_button">
<input type="submit" name="check_sum" value="Check my sum!" />
</div>
<!-- CLOSE THE FORM -->
</form>
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<!-- TITLE OF THE SITE -->
<title> Faso.comulu.com | Captcha sum </title>
<!-- MAKE THE SITE BEAUTIFULL -->
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Aldrich">
<?php
/****************************************
# Make two random number to count *
# (+ or -). And change in some cases *
# the number into letters to make it *
# for spammers harder to crack (almost *
# impossible because spambots can't *
# read) *
****************************************/
/****************************************
# Set an error, so we can display them *
****************************************/
$error = '';
/****************************************
# Make a random captcha image, call the *
# images like this: captcha1, captcha2 *
****************************************/
$image = 'images/captcha'.rand(1,8).'.jpg';
/****************************************
# Create two random numbers to decide *
# if we make a plus or min exercise *
****************************************/
$plusmin = rand(1,2);
/****************************************
# Make some random numbers, number1 is *
# between 10 and twenty and the second *
# one between 1 and 9 because PHP can't *
# count 0 or -0 *
****************************************/
$number1 = rand(10,20);
$number2 = rand(1,9);
/****************************************
# Make the numbers change into letters *
# (three,seven,nine,twelve,fifteen, *
# seventeen,nineteen aren't changing) *
****************************************/
$replace = array('1' => 'one', '2' => 'two', '4' => 'four', '5' => 'five', '6' => 'six', '8' => 'eight', '10' => 'ten', '11' => 'eleven', '13' => 'thirteen', '14' => 'fourteen', '16' => 'sixteen', '18' => 'eighteen', '20' => 'twenty');
/****************************************
# Check if the random number is in the *
# array and replace it with the letters *
# variation *
****************************************/
if(array_key_exists($number1, $replace)) {
$display1 = $replace[$number1]; }
else {
$display1 = $number1; }
/****************************************
# Do the same as above, but now with *
# number two *
****************************************/
if(array_key_exists($number2, $replace)) {
$display2 = $replace[$number2]; }
else {
$display2 = $number2; }
/****************************************
# Now go back to the plus or min case *
# and display the good one, if it is 1, *
# the sum is + else it is - *
****************************************/
if($plusmin == 1) {
$display = $display1.' + '.$display2;
$sumcheck = $number1 + $number2; }
else {
$display = $display1.' - '.$display2;
$sumcheck = $number1 - $number2; }
/****************************************
# If the submitter wants that we check *
# the captcha sum. *
****************************************/
if(isset($_POST['check_sum'])) {
/****************************************
# Trim the answer and set it as *
# variable $answer *
****************************************/
$answer = trim($_POST['sum_answer']);
/****************************************
# Rewrite the sum if the answer isn't *
# numeric (only try it) *
****************************************/
if(!is_numeric($answer)) {
/****************************************
# Change it now *
****************************************/
$replace = array('one' => '1', 'two' => '2', 'three' => '3', 'four' => '4', 'five' => '5', 'six' => '6', 'seven' => '7', 'eight' => '8', 'nine' => '9', 'ten' => '10', 'eleven' => '11', 'twelve' => '12', 'thirteen' => '13', 'fourteen' => '14', 'fifteen' => '15', 'sixteen' => '16', 'seventeen' => '17', 'eighteen' => '18', 'nineteen' => '19', 'twenty' => '20', 'twenty-one' => '21', 'twenty-two' => '22', 'twenty-three' => '23', 'twenty-four', '24', 'twenty-five' => '25', 'twenty-six' => '26', 'twenty-seven' => '27', 'twenty-eight' => '28', 'twenty-nine' => '29');
/****************************************
# If the answer is in the array above, *
# change it into numbers *
****************************************/
if(array_key_exists($answer, $replace)) {
$answer = $replace[$answer]; } }
/****************************************
# Now we tried to change the number and *
# everything like that, so we can check *
# the inserted answer *
****************************************/
if($_SESSION['sum'] == $answer) {
$error = '<div class="error">Your answer is correct!</div>'; }
else {
$error = '<div class="error">Your answer isn\'t correct!</div>'; } }
/****************************************
# Unset the session at the end of the *
# code and set a new one *
****************************************/
unset($_SESSION['sum']);
$_SESSION['sum'] = $sumcheck;
?>
</head>
<body>
<div class="wrapper">
Captcha Sum
</div>
<div class="container">
<!-- ERROR -->
<?php echo $bError; ?>
<!-- CAPTCHA IMAGE -->
<div class="captcha_background">
<img src="<?php echo $aImage; ?>" />
</div>
<!-- THE SUM -->
<div class="captcha_sum">
<?php echo $aDisplay; ?>
</div>
<!-- START THE FORM -->
<form action="" method="POST">
<!-- THE ANSWER BOX -->
<div class="answer_sum">
<input type="text" name="sum_answer" value="Insert answer" onBlur="if(this.value.length == 0) this.value='Insert answer';" onClick="if(this.value == 'Insert answer') this.value='';" />
</div>
<!-- ANSWER BUTTON -->
<div class="anwer_button">
<input type="submit" name="check_sum" value="Check my sum!" />
</div>
<!-- CLOSE THE FORM -->
</form>
</div>
</body>
</html>