2014-03-06 72 views
0

編輯過的實際密鑰「我正在用REcaptcha實現一個簡單的登錄表單 REcaptcha給了我這個錯誤: 」reCAPTCHA輸入不正確。回去再試試。(reCAPTCHA的說:不正確,驗證碼-SOL)」 這是我的代碼:Recaptcha「incorrect-captcha-sol」

的index.php

<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> 
<tr> 
<form name="form1" method="post" action="verify.php"> 
<td> 
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> 
<tr> 
<td colspan="3"><strong>Member Login </strong></td> 
</tr> 

<tr> 
<td width="78">Username</td> 
<td width="6">:</td> 
<td width="294"><input name="myusername" type="text" id="myusername"></td> 
</tr> 

<tr> 
<td>Password</td> 
<td>:</td> 
<td><input name="mypassword" type="text" id="mypassword"></td> 
</tr> 

<tr> 
<td>&nbsp;</td> 
<td>&nbsp;</td> 
<td><input type="submit" name="Submit" value="Login"></td> 

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

<html> 
<title>Title Dolan Webiste</title> 
<body> 

<script type="text/javascript" 
    src="http://www.google.com/recaptcha/api/challenge?k=actual_key_redacted"> 
    </script> 
    <noscript> 
    <iframe src="http://www.google.com/recaptcha/api/noscript?k=actual_key_redacted" 
     height="300" width="500" frameborder="0"></iframe><br> 
    <textarea name="recaptcha_challenge_field" rows="3" cols="40"> 
    </textarea> 
    <input type="hidden" name="recaptcha_response_field" 
     value="manual_challenge"> 
    </noscript> 

</body> 
</html> 

Verify.php

<?php 
echo "<pre> _POST: =========\n"; 
print_r($_POST); 
echo "\n=========\n</pre>"; 
?> 

<?php 
    require_once('recaptchalib.php'); 
    $privatekey = "private_key_here"; 
    $resp = recaptcha_check_answer ($privatekey, 
           $_SERVER["REMOTE_ADDR"], 
           $_POST["recaptcha_challenge_field"], 
           $_POST["recaptcha_response_field"]); 

    if (!$resp->is_valid) { 
    // What happens when the CAPTCHA was entered incorrectly 
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . 
     "(reCAPTCHA said: " . $resp->error . ")"); 
    } else { 
    // Your code here to handle a successful verification 
    } 
?> 

我有不知道我做錯了什麼 任何幫助?

ps是的我在同一個目錄中有recaptchalib.php。

+1

你表明你進入你的公鑰在HTML,但你是不是表示你進入你的私人關鍵在PHP中。你是否? – Sparky

+0

我做過了,我試圖隱藏自己的私鑰(可能會被濫用) – none

+0

我很確定我輸入了正確的密碼,我複製粘貼它。 – none

回答

0

看到這個...

$_POST["recaptcha_challenge_field"], 
$_POST["recaptcha_response_field"] 

$_POST變量數組後提交來自form數據。問題是,如果您未能將這些字段放入form容器中,表單數據帖子數組如何包含recaptcha_challenge_fieldrecaptcha_response_field

必須把reCAPTCHA小工具裏面你form容器,或<form></form>標籤之間。

<form name="form1" method="post" action="verify.php"> 

    .... the rest of your form here 

    <script type="text/javascript" 
    src="http://www.google.com/recaptcha/api/challenge?k=actual_key_redacted"> 
    </script> 
    <noscript> 
    <iframe src="http://www.google.com/recaptcha/api/noscript?k=actual_key_redacted" 
     height="300" width="500" frameborder="0"></iframe><br> 
    <textarea name="recaptcha_challenge_field" rows="3" cols="40"> 
    </textarea> 
    <input type="hidden" name="recaptcha_response_field" 
     value="manual_challenge"> 
    </noscript> 

</form> 

但是,不知道爲什麼,當你做了沒有注意到丟失後數據的print_r($_POST);

+0

這仍然有效嗎?還是應該使用[google recaptcha](https://developers.google.com/recaptcha/docs/start)發佈的示例? –

+0

@IronFist,AFAIK,這個答案沒有錯,它適用於你已經鏈接的相同版本。如果您有相反的信息,請分享。 – Sparky

+0

我的不好,我沒有意識到你的答案是爲殘疾JS用戶。沒有什麼問題。 –