File tree Expand file tree Collapse file tree 2 files changed +108
-0
lines changed Expand file tree Collapse file tree 2 files changed +108
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ if (!defined ("FLAG_OK " )) { http_response_code (403 ); die ();}
3
+
4
+ session_start ();
5
+ $ continut = '' ;
6
+ $ ecuatie = '' ;
7
+
8
+ function handle_post (){
9
+ global $ continut ;
10
+ global $ ok ;
11
+
12
+ $ rezultat = intval ($ _SESSION ["rezultat " ]);
13
+ unset($ _SESSION ["rezultat " ]);
14
+
15
+ if (!isset ($ _SESSION ["rezultat " ])) {
16
+ $ continut = 'Nu a fost generata nici o ecuatie pentru dumneavoastra. ' ;
17
+ }
18
+ elseif (!isset ($ _POST ["rezultat " ])) {
19
+ $ continut = 'Pentru a trece la pasul urmator trebuie sa rezolvati ecuatia. ' ;
20
+ }
21
+ elseif ($ _POST ["rezultat " ] != $ _SESSION ["rezultat " ]) {
22
+ $ continut = 'Solutia oferita nu este valida. ' ;
23
+ }
24
+ elseif (intval ($ _POST ["rezultat " ]) === $ _SESSION ["rezultat " ]) {
25
+ $ continut = 'Felicitari soluția oferita este cea corectă. ' ;
26
+ }
27
+ else {
28
+ # Acest caz nu a fost tratat.
29
+ http_response_code (400 );
30
+ die ();
31
+ }
32
+ }
33
+
34
+
35
+ function handle_get (){
36
+ global $ ecuatie ;
37
+
38
+ $ coeficient = rand (1 , 5 );
39
+ $ operand = rand (1 , 5 );
40
+ $ necunoscuta = rand (1 , 20 );
41
+ $ rezultat = $ coeficient * $ necunoscuta + $ operand ;
42
+
43
+ $ _SESSION ["rezultat " ] = $ necunoscuta ;
44
+ $ ecuatie = "$ coeficient x + $ operand = $ rezultat " ;
45
+ }
46
+
47
+ function main (){
48
+ $ method = $ _SERVER ['REQUEST_METHOD ' ];
49
+ switch ($ method ) {
50
+ case 'POST ' :
51
+ handle_post ();
52
+ break ;
53
+ case 'GET ' :
54
+ handle_get ();
55
+ break ;
56
+ default :
57
+ die ("Pentru moment aplicația nu suportă această metodă. " );
58
+ break ;
59
+ }
60
+ }
61
+
62
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+ define ("FLAG_OK " , true );
3
+ require ('_include/_captcha.php ' );
4
+ main ();
5
+ ?>
6
+
7
+ <!doctype html>
8
+ <html lang="ro">
9
+
10
+ <head>
11
+ <meta charset="utf-8">
12
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
13
+ <title>Tuxy captcha</title>
14
+
15
+ <meta name="author" content="Tuxy Pinguinescu" />
16
+ <meta name="description" content="" />
17
+ <meta name="viewport" content="width=device-width, initial-scale=1">
18
+ </head>
19
+
20
+ <body>
21
+ <header>
22
+ <h1>Tuxy Capcha</h1>
23
+ </header>
24
+
25
+ <section id="continut">
26
+ <?php if (isset ($ continut )) echo $ continut ; ?>
27
+ </section>
28
+
29
+ <section id="captcha">
30
+ <?php if (!empty ($ ecuatie )) { ?>
31
+ <form action="#" method="post">
32
+ <p>Pentru a trece la pasul următor trebuie să rezolvați următoarea ecuația:</p>
33
+ <?php echo $ ecuatie ; ?>
34
+ <label for="rezultat">Rezultat:</label>
35
+ <input type="text" name="rezultat">
36
+
37
+ <input type="submit">
38
+ </form>
39
+ <?php } ?>
40
+ </section>
41
+
42
+ <footer>
43
+ <h3>Toate drepturile rezervate. Tuxy Pinguinesc</h3>
44
+ </footer>
45
+ </body>
46
+ </html>
You can’t perform that action at this time.
0 commit comments