17

サイトに reCAPTCHA を追加しようとしていますがincorrect-captcha-sol、回答を送信するとエラーが発生し続けます。

私が次のことをするのが正しいかどうか誰かに教えてもらえますか?

contact.php を含む一般的な index.php があります。contact.php に、次のコードを挿入しました。

require_once('recaptchalib.php');
$publickey = "XXXX";
$privatekey = "XXXX";

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

if ($_POST['submit']) {
    $message = $_POST['message_txt'];
    $name = $_POST['name_txt'];
    $email = $_POST['email_txt'];
    
    $emailBody = $message;
    $to = 'xx';
    $from = $name.' <'.$email.'>';
    $subject = 'XX Website Enquiry';
    $headers = 'From: '.$from;  
        
    $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
    
    if ($resp->is_valid) {
        echo 'captcha correct';
        if (mail($to,$subject,$emailBody,$headers)) {
            //echo 'mail sent';
            $confirmation = 'sent';
        }
        else {
            //echo 'mail not sent';
            $confirmation = 'error';
        }
    } else {
        # set the error code so that we can display it. You could also use
        # die ("reCAPTCHA failed"), but using the error message is
        # more user friendly
        
        $error = $resp->error;
        
        echo $error;
    }
}

私のHTMLでは、次のようにCAPTCHAを挿入しました:

<form name="contactForm" method="post" action="index.php?id=contact&action=submit#contact">
    <tr><td>Name</td><td><div align="right">
        <input type="text" name="name_txt" class="input">
        </div></td></tr>
    <tr><td>Email</td><td><div align="right">
        <input type="text" name="email_txt" class="input">
    </div></td></tr>
    <tr><td height="10"></td></tr>
    <tr><td colspan="2">Message</td></tr>
    <tr><td colspan="2"><textarea name="message_txt" class="textarea" style="width:200px; height:100px"></textarea></td></tr>
    <tr><td colspan="2"><?php echo recaptcha_get_html($publickey, $error); ?></td></tr>
    <tr><td colspan="2" style="padding-top:10px;"><input type="image" src="images/header_06.gif" name="submit" value="submit"></td></tr>
</form>

私が何か間違ったことをしていることはわかりませんが、助けていただければ幸いです。

4

7 に答える 7

22

私はこれを解決しました。これは私が遭遇した中で最も珍しいことの1つであり、私の構文は以前は次のとおりでした。

<table>
  <form>
    <tr><td></td></tr>
  </form>
</table>

私はそれをこれに変更しました:

<form>
  <table>
    <tr><td></td></tr>
  </table>
</form>

この切り替えにより、突然recaptcha_response_fieldrecaptcha_challenge_fieldがフォームに値をポストします。

すべてのMYフォーム変数が切り替え前にポストバックされたため、これがなぜかはわかりません。

ポインタをありがとう。

于 2009-08-12T11:58:26.907 に答える
15

ローカルホストからこれを行っていますか?

localhostGoogle reCaptcha設定で検証を行うために許可されたドメインに追加することで、この問題を解決します

ドメイン reCaptcha 設定

于 2021-06-27T09:31:50.363 に答える
9

チェックを2回投稿する場合(たとえば、javascriptから1回、php経由で1回)、APIではソリューションが有効なものを1回しか返さないため、2番目のチェックは失敗します。

お役に立てば幸い、ジョシュ

于 2009-08-12T07:43:13.303 に答える
5

これは、フォームを tr の外側に置くことはできないためです.....テーブルの外側に置く必要があります.....フォームをテーブルに挿入することはできませんが、td に挿入することはできます。

于 2010-05-08T19:31:56.037 に答える
2

私の場合、エラーは指定せずにフォームを設定することでした:

メソッド="投稿"

乾杯!

于 2010-08-15T10:21:35.163 に答える
0

正しい単語を入力してもよろしいですか?

これはrecaptchaのWebサイトからのものです:

Line 1       "true" or "false". True if the reCAPTCHA was successful
Line 2  if Line 1 is false, then this string will be an error code. reCAPTCHA can 
    display the error to the user (through the error parameter of api.recaptcha.net/challenge).
     Implementations should not depend on error code names, 
as they may change in the future.


    Example: If your response looks like this:

    false
    **incorrect-captcha-sol**

    ... you can add '&error=incorrect-captcha-sol' to the challenge request URL, 
and the user will get an error code.
于 2009-08-12T07:44:01.023 に答える
0

スクリプトのルート ディレクトリで、php.ini を次のように設定します。

allow_url_fopen=オン

于 2018-03-26T22:32:15.230 に答える