<html>
<body>
<form action="" method="post">
<?phprequire_once('e/admin/recaptchalib.php');// Get a key from http://recaptcha.net/api/getkey
$publickey = "6L...X";
$privatekey = "6L...";# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = 'Error!';# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]); if ($resp->is_valid) {
echo "You got it!";
} else {
# set the error code so that we can display it
$error = $resp->error;
}
}
echo recaptcha_get_html($publickey, $error);
?>
<br/>
<input type="submit" value="submit" />
</form>
</body>
</html>
为什么不输入验证码也可以提交呢?怎么验证啊?验证码用的是recapcha, http://recaptcha.net/plugins/php/, 但是按照上面说的也是不行的
<body>
<form action="" method="post">
<?phprequire_once('e/admin/recaptchalib.php');// Get a key from http://recaptcha.net/api/getkey
$publickey = "6L...X";
$privatekey = "6L...";# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = 'Error!';# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]); if ($resp->is_valid) {
echo "You got it!";
} else {
# set the error code so that we can display it
$error = $resp->error;
}
}
echo recaptcha_get_html($publickey, $error);
?>
<br/>
<input type="submit" value="submit" />
</form>
</body>
</html>
为什么不输入验证码也可以提交呢?怎么验证啊?验证码用的是recapcha, http://recaptcha.net/plugins/php/, 但是按照上面说的也是不行的
2.可以看见的说,提交后有什么显示
3.没有显示东西的话,试试改$error = $resp->error; 成 echo "invalid"; 再提交看看
能看见图片
如果不输入直接提交后没有显示, 重新load图片(不管输入不输入字母),如果输入,会显示错误.
改了以后, 不输入直接提交,没有显示,只是重新load图片.随便输入,显示invalid.我已经把两个key值pm给你了, 你可以直接在本地调试一下. 那个lib文件可在这里下:http://recaptcha.googlecode.com/files/recaptcha-php-1.10.zip, 或者官方http://code.google.com/p/recaptcha/downloads/list?q=label:phplib-Latest现在的问题是, 能显示图片,但起不了验证作用. 我把它用在登陆页面, 和原来一样, 验证码输不输入, 是否错误, 完全不影响登陆.有兴趣的我可以pm两个key值,可在本地调试用.(或者注册获得自己的key)
<body>
<form action="" method="post">
<?phprequire_once('recaptchalib.php');// Get a key from http://recaptcha.net/api/getkey
$publickey = "";
$privatekey = "";# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;# was there a reCAPTCHA response?
if (isset($_POST["recaptcha_response_field"])) {
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]); if ($resp->is_valid) {
echo "验证码正确";
//豋入程序放这里
} else {
# set the error code so that we can display it
echo "验证码不正确,错误:";
echo $error = $resp->error;
}
}
echo recaptcha_get_html($publickey, $error);
?>
<br/>
<input type="submit" value="submit" />
</form>
</body>
</html>
<form name="login" method="post" action="enews.php" onSubmit="return CheckLogin(document.login);">
<input type="hidden" name="enews" value="login">
<table callspacing="0" cellpadding="0" class="loginbox">
<tr>
<td class="logo"><p>请输入你的密码</p></td>
<td>
<table callspacing="0" cellpadding="0" class="loginform">
<tr>
<th>用户名:</th>
<td colspan="2"><input name="username" type="text" class="t_input"></td>
</tr>
<tr>
<th>密 码:</th>
<td colspan="2"><input type="password" name="password" class="t_input" /></td>
</tr>
<tr>
<td height="27" colspan="3">
<?phprequire_once('recaptchalib.php');// Get a key from http://recaptcha.net/api/getkey
$publickey = "6LelSgIAAAAAAEXEBjQtPNHdEwwulCUfCg4z8wwX";
$privatekey = "6LelSgIAAAAAAOln_J9Oi5FvO2nrHMryeH-a_dnm";# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
}
}
echo recaptcha_get_html($publickey, $error);
?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="27"> </td>
<td colspan="2" valign="bottom">
<input name="imageField" type="submit" value="确定" class="submit">
</td>
</tr>
</table>
</form>
不好意思, 怎么把登入程序放进去啊?比如我想改的这个登陆页面
require_once('recaptchalib.php');
echo recaptcha_get_html($publickey, null);
登入页,应该是enews.php吧,加下面的
require_once('recaptchalib.php');// Get a key from http://recaptcha.net/api/getkey
$publickey = "6LelSgIAAAAAAEXEBjQtPNHdEwwulCUfCg4z8wwX";
$privatekey = "6LelSgIAAAAAAOln_J9Oi5FvO2nrHMryeH-a_dnm";# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
}
}
elseif($enews=="login")
{
$username=$_POST['username'];
$password=$_POST['password'];
$key=$_POST['key'];
$loginin=$username;
login($username,$password,$key,$_POST);
}
...
else
{printerror("ErrorUrl","history.go(-1)");}
db_close();
$empire=null;
改成
elseif($enews=="login")
{
$publickey = "6LelSgIAAAAAAEXEBjQtPNHdEwwulCUfCg4z8wwX";
$privatekey = "6LelSgIAAAAAAOln_J9Oi5FvO2nrHMryeH-a_dnm";
$response = null;
$error = null;
# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
$response = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if ( $response->is_valid ) {
$username=$_POST['username'];
$password=$_POST['password'];
$key=$_POST['key'];
$loginin=$username;
login($username,$password,$key,$_POST);}
}
}现在有点用了, 正确输入用户名和密码以及验证码可以正常登陆, 但如果输错一项, 则显示白屏,连系统原先有的错误信息也没了, 怎么办?
else
{printerror("ErrorUrl","history.go(-1)");}现在可以显示用户名和密码是否错误了, 但如果验证码错误, 会显示"您来自的链接不存在", 怎么让他既能显示系统原来的错误, 当验证码错误时又能显示验证码错误呢?
参考一些简单的例子,理解原理后自己边看手册边写吧。