Closed pippuccio76 closed 3 weeks ago
Hi, thanks for reporting, I'll fix the example.
Looks like the server doesn't return a valid JSON response. Check if the challengeurl
is correct and inspect the server response - it must return only the JSON-encoded challenge and nothing else, also include content-type: application/json
header.
your php example doesn't return Json .... Now i return json:
$challenge = Altcha::createChallenge($options);
log_message('debug', "Challenge created: " . json_encode($challenge) );
log_message('debug', "Tipo variabile : " . gettype($challenge) );
return json_encode($challenge) ;
json seem ok :
DEBUG - 2024-09-12 19:11:07 --> Challenge created: {"algorithm":"SHA-256","challenge":"fe6295348cd9cf98e8c5e6b3d65b3af5f714cfcc72544b4fdb9b2ba223174e57","maxnumber":50000,"salt":"b6be1c392202dc0e69e34166","signature":"197f28fb07e03942dc049cebd19ca23c1fd082ae38215e3a34be58f506112018"}
ALTCHA [name=altcha] SyntaxError: Unexpected non-whitespace character after JSON at position 234 (line 2 column 1)
The library altcha-lib-php
is just a library, not a server and thus it does not encode any data. For more comprehensive example, please refer to the altcha-starter-php repository, which includes a complete http server with encoding.
Make sure the response contains only the JSON-encoded challenge and nothing else.
Hi , i use your code , js and php...
PHP example have an error:
this: [CODE] $payload = [ 'algorithm' => $challenge['algorithm'], 'challenge' => $challenge['challenge'], 'number' => 12345, // Example number 'salt' => $challenge['salt'], 'signature' => $challenge['signature'], ];
[/CODE]
must change to :
[CODE] $payload = [ 'algorithm' => $challenge->algorithm, 'challenge' => $challenge->challenge, 'number' => 43267, // Example number 'salt' => $challenge->salt, 'signature' => $challenge->signature, ];
[/CODE]
because return an object instead of array.
Now i have this error :
altcha.js:1186 ALTCHA [name=altcha] SyntaxError: Unexpected token '<', " <script i"... is not valid JSON
How can i solve it ?