fabianwennink / IconCaptcha-PHP

A self-hosted, customizable, easy-to-implement and user-friendly captcha for PHP.
https://www.fabianwennink.nl/projects/IconCaptcha/
MIT License
134 stars 25 forks source link

Getting 400 Bad Request whenever the wrong image is selected #20

Closed YoussefE123 closed 1 year ago

YoussefE123 commented 1 year ago

While testing, I noticed an error in the console, which is also present in the network tab : it's a "400 Bad Request". Then after following the PHP code, it seems this only triggers when I select the wrong image, and more precisely in the file "captcha-request.php" (line 68).

I managed to fix this by adding an "else" statement : else{ header('HTTP/1.0 204 No Content'); }

"201" code also works, but 204 seems more appropriate, and setting 200 gives the same error, so it seems the JS file only checks for 200 response as "Verified", and considers all other response codes as "Wrong" ! so for this case, I think 204 response is the best choice to fix this.

fabianwennink commented 1 year ago

Hi @YoussefE123! The 400 status being returned when selecting an incorrect icon was implemented on purpose at the time. It was easier for AJAX requests to determine if the request succeeded or not, and also kind of made more sense to return an error instead of '200 OK' when it was.. not OK. However, I'm aware that returning a 400 status might not always be preferred, even though the error is only visible in the console and not causing any side effects.

I'm currently working on the next version of IconCaptcha (see develop branch) and will take this issue into account while making changes. I'm not sure if I will also be making changes to the current version.

Are you experiencing any issues related to the status 400 being returned, apart from it being logged to the console?

YoussefE123 commented 1 year ago

Apart from the console, everything seems to be OK. I already fixed this in my file, so it's ok if you won't update until the next version.

fabianwennink commented 1 year ago

Closing the issue. The change request has been noted and will be considered for the next release version.