Browse Source

Make sure question text is black, improve test sample

tags/v0.2
Skylar Ittner 2 years ago
parent
commit
70c45d24f7
3 changed files with 31 additions and 7 deletions
  1. 3
    2
      captcheck.js
  2. 3
    3
      test.html
  3. 25
    2
      test.php

+ 3
- 2
captcheck.js View File

@@ -1,5 +1,5 @@
1 1
 window.onload = function () {
2
-    var api_url = "http://192.168.25.1/captcheck/api.php";
2
+    var api_url = "https://captcheck.netsyms.com/api.php";
3 3
     var getJSON = function (url, callback) {
4 4
         var xhr = new XMLHttpRequest();
5 5
         xhr.open('GET', url, true);
@@ -13,7 +13,7 @@ window.onload = function () {
13 13
     getJSON(api_url + "?action=new", function (status, json) {
14 14
         /* Add custom styles */
15 15
         var styles = document.createElement('style');
16
-        styles.innerHTML = ".captcheck_box {font-family: Ubuntu, Arial, sans-serif; border: 1px solid #e0e0e0; border-radius: 3px; display: inline-block; padding: 3px; margin: 5px 2px 5px 1px; background-color: #f5f5f5;} .captcheck_answer_label > input {visibility: hidden; position: absolute;} .captcheck_answer_label > input + img {cursor: pointer; border: 2px solid transparent; border-radius: 3px; min-width: 32px; width: 18%; max-width: 64px;} .captcheck_answer_label > input:checked + img {cursor: pointer; border: 2px solid #424242; border-radius: 3px;} .captcheck_error_message { color: red; }";
16
+        styles.innerHTML = ".captcheck_box {font-family: Ubuntu, Arial, sans-serif; color: black; border: 1px solid #e0e0e0; border-radius: 3px; display: inline-block; padding: 3px; margin: 5px 2px 5px 1px; background-color: #f5f5f5;} .captcheck_label_message {color: black;} .captcheck_answer_label > input {visibility: hidden; position: absolute;} .captcheck_answer_label > input + img {cursor: pointer; border: 2px solid transparent; border-radius: 3px; min-width: 32px; width: 18%; max-width: 64px;} .captcheck_answer_label > input:checked + img {cursor: pointer; border: 2px solid #424242; border-radius: 3px;} .captcheck_error_message {color: red;}";
17 17
         document.body.appendChild(styles);
18 18
 
19 19
         /* Get captcha container div */
@@ -35,6 +35,7 @@ window.onload = function () {
35 35
             answer_div.innerHTML = answers;
36 36
             /* Create question */
37 37
             var question_div = document.createElement("div");
38
+            question_div.setAttribute("class", "captcheck_label_message");
38 39
             question_div.innerHTML = "Click on the <b>" + data.question + "</b>:";
39 40
 
40 41
             /* Add question and answers */

+ 3
- 3
test.html View File

@@ -1,14 +1,14 @@
1 1
 <!DOCTYPE html>
2 2
 <html>
3 3
     <head>
4
-        <title>Captcheck Test Page</title>
4
+        <title>Captcheck Sample Form</title>
5 5
         <meta charset="UTF-8">
6 6
         <meta name="viewport" content="width=device-width, initial-scale=1.0">
7 7
         <script src="captcheck.js"></script>
8 8
     </head>
9 9
     <body>
10
-        <form action="test.php" method="GET">
11
-            <input type="text" name="junk" placeholder="Junk" />
10
+        <form action="submit.php" method="POST">
11
+            <input type="text" name="form_field" placeholder="Some random form field" />
12 12
             <div id="captcheck_container">
13 13
             </div>
14 14
             <button type="submit">Submit Form</button>

+ 25
- 2
test.php View File

@@ -1,6 +1,29 @@
1 1
 <?php
2 2
 
3
-//header("Content-Type: application/json");
4 3
 header("Content-Type: text/plain");
5 4
 
6
-echo json_encode(["get" => $_GET, "api" => json_decode(file_get_contents("http://localhost/captcheck/api.php?action=verify&session_id=" . $_GET["captcheck_session_code"] . "&answer_id=".$_GET["captcheck_selected_answer"]), true)]);
5
+var_dump($_POST);
6
+
7
+
8
+
9
+$url = 'https://captcheck.netsyms.com/api.php';
10
+$data = [
11
+    'session_id' => $_POST['captcheck_session_code'],
12
+    'answer_id' => $_POST['captcheck_selected_answer'],
13
+    'action' => "verify"
14
+];
15
+$options = [
16
+    'http' => [
17
+        'header' => "Content-type: application/x-www-form-urlencoded\r\n",
18
+        'method' => 'POST',
19
+        'content' => http_build_query($data)
20
+    ]
21
+];
22
+$context = stream_context_create($options);
23
+$result = file_get_contents($url, false, $context);
24
+$resp = json_decode($result, TRUE);
25
+if (!$resp['result']) {
26
+    exit("\n\nCAPTCHA did not verify:" . $resp['msg']);
27
+} else {
28
+    exit("\n\nCAPTCHA verified!");
29
+}

Loading…
Cancel
Save