Return to Snippet

Revision: 24565
at March 7, 2010 06:16 by stephanepericat


Updated Code
/**
 * author : Stephane P. Pericat
 * date : 2010-03-01
 */

PHP Code:

<?php

require "recaptcha/recaptchalib.php";

if($_POST) {
    $resp = recaptcha_check_answer(
        "6LdrkwsAAAAAAHX2b45bn_...", //put your recaptcha private key here
        $_SERVER["REMOTE_ADDR"],
        $_POST["recaptcha_challenge_field"],
        $_POST["recaptcha_response_field"]
    );
    if ($resp->is_valid) {
        echo json_encode(true);
    } else {
        echo json_encode(false);
    }
}
?>

//-----------------------------------------------

Javascript front-end:

new Asset.javascript('http://api.recaptcha.net/js/recaptcha_ajax.js');

$(document.body).addEvent('submit', function(event) {
    event.stop();
    var challenge = Recaptcha.get_challenge();
    var response = Recaptcha.get_response();
    var control = new Request.JSON({
        url: 'control.php',
        data : {
            recaptcha_challenge_field : challenge,
            recaptcha_response_field : response
        },
        method: 'post',
        onComplete : function (result) {
            if(result == true) {
                Recaptcha.destroy();
                console.log(result);
            } else {
                Recaptcha.reload();
            }
        }
    }).send();
});

Revision: 24564
at March 7, 2010 05:55 by stephanepericat


Updated Code
PHP Code:

<?php

require "recaptcha/recaptchalib.php";

if($_POST) {
    $resp = recaptcha_check_answer(
        "6LdrkwsAAAAAAHX2b45bn_...", //put your recaptcha private key here
        $_SERVER["REMOTE_ADDR"],
        $_POST["recaptcha_challenge_field"],
        $_POST["recaptcha_response_field"]
    );
    if ($resp->is_valid) {
        echo json_encode(true);
    } else {
        echo json_encode(false);
    }
}
?>

//-----------------------------------------------

Javascript front-end:

new Asset.javascript('http://api.recaptcha.net/js/recaptcha_ajax.js');

$(document.body).addEvent('submit', function(event) {
    event.stop();
    var challenge = Recaptcha.get_challenge();
    var response = Recaptcha.get_response();
    var control = new Request.JSON({
        url: 'control.php',
        data : {
            recaptcha_challenge_field : challenge,
            recaptcha_response_field : response
        },
        method: 'post',
        onComplete : function (result) {
            if(result == true) {
                Recaptcha.destroy();
                console.log(result);
            } else {
                Recaptcha.reload();
            }
        }
    }).send();
});

Revision: 24563
at March 4, 2010 02:31 by stephanepericat


Updated Code
PHP Code:

<?php

require "recaptcha/recaptchalib.php";

if($_POST) {
    $resp = recaptcha_check_answer(
        "6LdrkwsAAAAAAHX2b45bn_...", //put your recaptcha private key here
        $_SERVER["REMOTE_ADDR"],
        $_POST["recaptcha_challenge_field"],
        $_POST["recaptcha_response_field"]
    );
    if ($resp->is_valid) {
        echo json_encode(true);
    } else {
        echo json_encode(false);
    }
}
?>

//-----------------------------------------------

Javascript front-end:

$(document.body).addEvent('submit', function(event) {
    event.stop();
    var challenge = Recaptcha.get_challenge();
    var response = Recaptcha.get_response();
    var control = new Request.JSON({
        url: 'control.php',
        data : {
            recaptcha_challenge_field : challenge,
            recaptcha_response_field : response
        },
        method: 'post',
        onComplete : function (result) {
            if(result == true) {
                Recaptcha.destroy();
                console.log(result);
            } else {
                Recaptcha.reload();
            }
        }
    }).send();
});

Revision: 24562
at March 4, 2010 02:29 by stephanepericat


Initial Code
PHP Code:

<?php

require "recaptcha/recaptchalib.php";

if($_POST) {
    $resp = recaptcha_check_answer(
        "6LdrkwsAAAAAAHX2b45bn_6Mfzg4BfpE75AmVkPE",
        $_SERVER["REMOTE_ADDR"],
        $_POST["recaptcha_challenge_field"],
        $_POST["recaptcha_response_field"]
    );
    if ($resp->is_valid) {
        echo json_encode(true);
    } else {
        echo json_encode(false);
    }
}
?>

//-----------------------------------------------

Javascript front-end:

$(document.body).addEvent('submit', function(event) {
    event.stop();
    var challenge = Recaptcha.get_challenge();
    var response = Recaptcha.get_response();
    var control = new Request.JSON({
        url: 'control.php',
        data : {
            recaptcha_challenge_field : challenge,
            recaptcha_response_field : response
        },
        method: 'post',
        onComplete : function (result) {
            if(result == true) {
                Recaptcha.destroy();
                console.log(result);
            } else {
                Recaptcha.reload();
            }
        }
    }).send();
});

Initial URL

                                

Initial Description
A simple JSON request to validate a captcha control (using the php plugin provided by Recaptcha)

Initial Title
Captcha with Mootools

Initial Tags
php

Initial Language
JavaScript