2011-02-16 60 views
2

所以我试图让recaptcha与我的表单一起工作。这是我的表单代码。验证用户的答案没有插件reCAPTCHA

<form action="" method="post"> 
<input type="text" name="text4" id="text4" style="width:400px" /><br/><br/>' . '<script type="text/javascript" 
    src="http://www.google.com/recaptcha/api/challenge?k=XXXXXXXXXXXXXXXXXX"> 
</script> 
<noscript> 
    <iframe src="http://www.google.com/recaptcha/api/noscript?k=XXXXXXXXXXXXXXXXXX" 
     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><input type="button" value="Submit"/> 

我试图使用的ReCaptcha无插件。很容易让它显示,但我很难验证输入。任何人都知道如何在没有插件的情况下进行验证? 非常感谢。

+0

你是什么意思的“插件”?你想使用它没有PHP? (然后请删除该标签并添加Javascript和HTML。) – mario 2011-02-16 03:38:01

回答

3

您的服务器端代码,让reCAPTCHA的工作,应该是类似什么张贴在这里的东西:

有没有办法让reCAPTCHA的工作,不使用的解决方案与此类似,可以使用任何服务器端语言。这里是代码:

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

$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 
}