I'm sure there is a solution for that, I've already try to google what I'm looking for but no anser yet, So here is my little problem, I have a form with captcha, the captcha put it's orignal string in $_SESSION['PASSWORD']
, so I'd like to verify that user tape the same string as in the $_SESSION['PASSWORD']
.
Well I think I need a little ajax here, before I submit the form I have to check The $_SESSION['PASSWORD']
with the ajax and compare it with what user tape
Any help please, 'I'm not pro in ajax ' it would be great that you make it very simple form me.
Create a new php file and do a ajax request to that file. Than check if you get true or false back.
session_start();
if($_SESSION['PASSWORD'] == $_POST['PASSWORD']) {
echo "true";
}
echo "false";
Note: this is not very safe. It's better to check it when you submit your form (assuming thats the reason you use captcha). It doesn't matter if you post the form with ajax or normal way of submitting forms. If you only check captcha with ajax than posting data is still possible with a custom http request or even more simple by disabling javascript (what most bots do).
HTML
<input type="text" id="captcha" name="captcha"> <!-- This is your captcha input -->
JQuery:
$.get('verify.php', { captcha: $('#captcha').val() }, function(data){
if(data === 'OK'); //Validation is ok
else; //Validation is wrong
});
PHP (verify.php):
<?php
session_start();
if($_GET['captcha'] === $_SESSION['password']) echo 'OK';
else echo 'ERROR';
exit();
?>
That's it, hope you accept the answer seeing your acceptance rate is just 20%