我在基于PHP的项目上有一个反馈网页。反馈页面有一个表格,上面有我需要的所有字段,我把recaptcha显示在那里,它工作正常:一切都正确显示,并根据谷歌手册功能。表单“action”设置为另一个页面,该页面应该只检查recaptcha,防止sql注入并将用户消息插入db。一切看似简单。
问题出在第二页。它只是返回空白,即使它不应该:
<?php
require_once('recaptchalib.php');
$privatekey = "my 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
//in this case the returned page is totally blank
echo <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Error</title>
</head>
<body bgcolor="WhiteSmoke">
EOT;
switch ($_POST["lang"]) {
case "en":
echo <<<EOT
<table width="100%" height="100%" border="0" cellspacing="10" align="center">
<tr>
<td width="100" height="100" align="center" valign="middle"><h3>CAPTCHA failed ($resp->error)!</h3></td>
</tr>
</table>
<meta HTTP-EQUIV='REFRESH' content='3; url=feedback_en.php'>
</body>
</html>
EOT;
break;
//here go other possible $_POST['lang'] values which i removed from the sample since its irrelevant
}
} else {
// Your code here to handle a successful verification
//in this case the page returns totally blank either
//here goes some db stuff
//here goes sql injection check which is also skipped for this code
//more db stuff
switch ($_POST["lang"]) {
case "en":
echo <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Thank you!</title>
<meta HTTP-EQUIV='REFRESH' content='3; url=feedback_en.php'>
</head>
<body bgcolor="WhiteSmoke">
<table width="100%" height="100%" border="0" cellspacing="10" align="center">
<tr>
<td width="100" height="100" align="center" valign="middle"><h3>Thank you for the feedback, with your help this service will be better!</h3></td>
</tr>
</table>
</body>
</html>
EOT;
break;
//and so on...
} //end of switch
//and we have nothing
}
?>
如代码中所述,无论测试结果如何,输出页面都是空白的。如果让recaptcha字段完全为空,它只会有点像样。它根据这个想法返回HTML,文本为“CAPTCHA failed(incorrect-captcha-sol)!”