1

こんにちは、私のページの連絡先ページで reCaptcha を使用しています。PHPでフォームを送信する前に単語をチェックしたい。だから私はAjaxでそれをやった。これが私のコードです。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Re captcha</title>
<script type="text/javascript" src="jquery-1.2.3.js"></script>
<script type="text/javascript">
function validateCaptcha()
{

challengeField =  $("input#recaptcha_challenge_field").val();
responseField = $("input#recaptcha_response_field").val();

alert(challengeField);
alert(responseField);
//return false;
var html = $.ajax({
type: "POST",
url: "ajax.recaptcha.php",
data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
async: false
}).responseText;

if(html == "success")
{
   // $("#captchaStatus").html("Success. Submitting form.");
   // return false;
    // Uncomment the following line in your application
    //load_ajax();
    alert("Captcha success..");
    return true;
}
else
{
    $("#captchaStatus").html("Image verification failed);
    Recaptcha.reload();
    return false;
}
}
</script>

</script>
</head>

<body>
<div style="height:300px;width:350px;margin:auto;background:#969;padding:20px;>
<form action = "javascript:void(null);" name="frmSubmit" method="post" onsubmit="return validateCaptcha();">
<label>Name</label><br />
<input type="text" name="txtName" id="NameTextBox" />
<br />
<label>E Mail</label><br />
<input type="text" name="txtEmail" id="EmailTextBox" />
<br />
<br />
<?php

 require_once('captcha/recaptchalib.php');

 // Get a key from https://www.google.com/recaptcha/admin/create

 //Localhost

  $publickey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
  $privatekey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";



  # the response from reCAPTCHA
  $resp = null;
  # the error code from reCAPTCHA, if any
  $error = null;

  # was there a reCAPTCHA response?
   if ($_POST["recaptcha_response_field"]) {
    $resp = recaptcha_check_answer ($privatekey,
                                    $_SERVER["REMOTE_ADDR"],
                                    $_POST["recaptcha_challenge_field"],
                                    $_POST["recaptcha_response_field"]);

    if ($resp->is_valid) {
            echo "You got it!";
    } else {
            # set the error code so that we can display it
            $error = $resp->error;
    }
    }
    echo recaptcha_get_html($publickey, $error);
     ?>
     <br />
    <input   name="BtnSubmit"type="submit"onclick="MM_validateForm('NameTextBox','','R','EmailTextBox','','R');return document.MM_returnValue" value="Send" />

    </form>
    </div>
     <script type="text/javascript">
            var RecaptchaOptions = {
                theme : 'Red'
            };
        </script>
       </body>
       </html>

私が得ているエラーは chlenge filed(challengeField = $("input#recaptcha_challenge_field").val();) です 私が得ているのは正しくありません。このように見えます

03AHJ_Vut2oHufxF2RvOtWbL7PDrlbU0bj3OgVpxaRg0Ae6-_xjqcIxRJTqD-bnUdTwyeLepickvVC7XLe5kqoWLu1sYdx7ZlmVkEP5TrHA9jGH75kW0Wua6faimq4aRZ5RaOOI0KOoqD0gVOGfeRQ1fw5c5lw-l5WXQ
4

1 に答える 1

1

PHP サイトでの recaptcha 統合にこれを使用してみてください

Zend_Service_ReCaptchaを使用するだけです。このサービスは、数行で統合できます。

//Creating instance
$recaptcha = new Zend_Service_ReCaptcha($pubKey, $privKey);

//Display output
echo $recaptcha->getHTML();

//Handling input
$result = $recaptcha->verify(
    $_POST['recaptcha_challenge_field'],
    $_POST['recaptcha_response_field']
);

//And finally validate captcha
if ($result->isValid()) {
    //Cool!
}
于 2012-09-21T09:38:21.867 に答える