Subversion Repositories php_clientchallenge

Rev

Rev 4 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <!DOCTYPE HTML>
  2. <html>
  3.  
  4. <head>
  5.         <title>Example of server request using Client-Challenge in order to mitigate resource starvation</title>
  6.         <meta charset="utf-8">
  7.         <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  8.         <script src="https://cdnjs.cloudflare.com/ajax/libs/js-sha3/0.8.0/sha3.min.js"></script>
  9.         <script src="../ClientChallenge.js"></script>
  10.  
  11. <script>
  12.  
  13. let error_cb = function (request, status, error) {
  14.         $("#out").val("Error!");
  15. }
  16.  
  17. let callback = function(params, vts_validation_result) {
  18.         $.ajax({
  19.                 type: "POST",
  20.                 url: "ajax_example.php",
  21.                 data: {
  22.                         // This is required:
  23.                         "vts_validation_result": vts_validation_result,
  24.  
  25.                         // This you can set yourself:
  26.                         "action": "add_numbers",
  27.                         "a": params['a'],
  28.                         "b": params['b']
  29.                 },
  30.                 success: function(data) {
  31.                         $("#out").val(data["result"]);
  32.                 },
  33.                 error: error_cb
  34.         });
  35. }
  36.  
  37. function calc() {
  38.         var a = $("#in_a").val();
  39.         var b = $("#in_b").val();
  40.         var params = {
  41.                 "a": a,
  42.                 "b": b
  43.         };
  44.         $("#out").val("Please wait...");
  45.         vts_validated_call("ajax_get_challenge.php", callback, params, error_cb);
  46. }
  47.  
  48. </script>
  49. </head>
  50.  
  51. <body>
  52.  
  53. <h2>Example of server request using Client-Challenge in order to mitigate resource starvation</h2>
  54.  
  55. <p><input id="in_a" value="2"> + <input id="in_b" value="3"> = <input id="out"> <input type="button" onclick="calc()" value="Calculate"></p>
  56.  
  57. </body>
  58.  
  59. </html>
  60.