2009-08-12 31 views
8

我想向我的網站添加reCAPTCHA,但在提交答案時不斷收到incorrect-captcha-sol錯誤。需要幫助reCAPTCHA - 不斷變得不正確 - captcha-sol

任何人都可以告訴我,我是否正確地做了以下工作?

我有一個通用的index.php,其中包括contact.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> 

我看不到,我做錯什麼,但會感謝任何建設性的批評。

TIA

回答

19

我已經解決了這一點,這是最不尋常的事情,我所遇到的一個,我的語法是以前:

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

我改成了這個:

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

因爲這個開關,突然recaptcha_response_fieldrecaptcha_challenge_field將值發回到表單。

我不明白爲什麼這是因爲所有我的表單變量都在切換之前回傳。

感謝所有的指針。

7

如果您發佈兩次檢查 - 通過PHP的第二個會失敗,因爲API從JavaScript例如一次,一次只允許一個解決方案返回有效一次。

希望幫助, 喬希

0

你確定你在正確的單詞打字?

這個人是從recaptcha website :

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. 
5

這是因爲表單不能在tr的外面.....它必須在表格的outisde上.....表格不能插入到表格中,它可以插入到td中。

2

在我的情況下,錯誤是設置形式不指定:

方法= 「POST」

乾杯!