抱歉,如果以前有人问过这个问题,但我正在我的第一个网站上工作并且仍在学习。我正在尝试将验证码添加到从此处获取的联系表单http://www.captcha.net/并使用 PHP。目前它正在工作,但网站上提供的让它工作的代码如下:
<html>
<body> <!-- the body tag is required or the CAPTCHA may not show on some browsers -->
<!-- your HTML content -->
<form method="post" action="verify.php">
<?php
require_once('recaptchalib.php');
$publickey = "your_public_key"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
<input type="submit" />
</form>
<!-- more of your HTML content -->
</body>
</html>
并且它在不同文件(服务器端)上的验证码是:
<?php
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
}
?>
我想知道是否有办法让 if 语句(如果验证码错误)打开联系页面,但显示一个隐藏的 div,显示验证码错误,然后重试。