コード例 #1
0
 public function testIfReturnsFalseOnWrongAnswer()
 {
     $_SESSION['fenchallenge'] = "8/8/2N5/2n2k2/2K5/2r1B3/8/8";
     // Store the correct answer in session
     $noJs = false;
     $colorTolerance = false;
     $inputFen = 'k2rn3/8/8/8/8/4K3/8/1Q1R4';
     //  The wrong answer
     $validate = ChessCaptcha::validate($inputFen, $noJs, $colorTolerance);
     // Must be false
     $this->assertFalse($validate);
 }
コード例 #2
0
<?php

require_once "../vendor/autoload.php";
// Example only. Always sanitize user input!
isset($_POST['chesscaptchaposition']) ? $inputFen = filter_var($_POST['chesscaptchaposition'], FILTER_SANITIZE_STRING) : ($inputFen = null);
isset($_POST['ccnojschallenge']) ? $respNoJs = $inputFen = filter_var($_POST['ccnojschallenge'], FILTER_SANITIZE_STRING) : ($respNoJs = null);
$noJs = false;
$colorTolerance = false;
// Config param: Change this to true if you want to enable color tolerance
// when Js Is disabled
if ($respNoJs && $noJs == true) {
    // no js input only
    $inputFen = $respNoJs;
}
$validate = false;
// init
if ($inputFen) {
    $validate = \Elioair\ChessCaptcha\ChessCaptcha::validate($inputFen, $noJs, $colorTolerance);
}
if ($validate) {
    echo '{"valid":true}';
} else {
    echo '{"valid":false}';
}