/trunk/example/ajax_example.php |
---|
23,12 → 23,18 |
require_once __DIR__ . '/../ClientChallenge.class.php'; |
define('MAX_TIME', 10); // seconds |
require_once __DIR__ . '/config.inc.php'; |
if (isset($_REQUEST['action']) && ($_REQUEST['action'] === 'add_numbers')) { |
// Check request field "vts_validation_result" for valid response of the Challenge |
\ViaThinkSoft\RateLimitingChallenge\ClientChallenge::checkValidation(MAX_TIME); |
try { |
\ViaThinkSoft\RateLimitingChallenge\ClientChallenge::checkValidation(MAX_TIME, VTS_CS_SERVER_SECRET); |
} catch (\Exception $e) { |
$res = array("error" => $e->getMessage()); |
header('Content-Type:application/json'); |
die(json_encode($res)); |
} |
// Do your stuff here. Example: |
$a = $_REQUEST['a']; |
/trunk/example/ajax_get_challenge.php |
---|
23,6 → 23,6 |
require_once __DIR__ . '/../ClientChallenge.class.php'; |
define('COMPLEXITY', 500000); |
require_once __DIR__ . '/config.inc.php'; |
\ViaThinkSoft\RateLimitingChallenge\ClientChallenge::createChallenge(COMPLEXITY); |
\ViaThinkSoft\RateLimitingChallenge\ClientChallenge::createChallenge(COMPLEXITY, VTS_CS_SERVER_SECRET); |
/trunk/example/config.inc.php |
---|
0,0 → 1,22 |
<?php |
/* |
* php_clientchallenge |
* Copyright 2021 Daniel Marschall, ViaThinkSoft |
* |
* Licensed under the Apache License, Version 2.0 (the "License"); |
* you may not use this file except in compliance with the License. |
* You may obtain a copy of the License at |
* |
* http://www.apache.org/licenses/LICENSE-2.0 |
* |
* Unless required by applicable law or agreed to in writing, software |
* distributed under the License is distributed on an "AS IS" BASIS, |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* See the License for the specific language governing permissions and |
* limitations under the License. |
*/ |
define('VTS_CS_SERVER_SECRET', '1234567890'); // PLEASE CHANGE THIS VALUE TO SOMETHING RANDOM! |
define('MAX_TIME', 10); // seconds |
define('COMPLEXITY', 500000); |
/trunk/example/index.html |
---|
28,7 → 28,12 |
"b": params['b'] |
}, |
success: function(data) { |
if ("error" in data) { |
$("#out").val('ERROR'); |
alert(data["error"]); |
} else { |
$("#out").val(data["result"]); |
} |
}, |
error: error_cb |
}); |