我用验证码制作了一个表单脚本,这是它的一部分:
<?php
$captcha1 = rand(0,9);
$captcha2 = rand(0,9);
$captcha3 = rand(0,9);
$captcha4 = rand(0,9);
$captcha5 = rand(0,9);
$captchafinal = $captcha1.$captcha2.$captcha3.$captcha4.$captcha5;
$captchaimageholder = array("captcha0.png", "captcha1.png", "captcha2.png", "captcha3.png", "captcha4.png", "captcha5.png", "captcha6.png", "captcha7.png", "captcha8.png", "captcha9.png");
print_r($captchafinal);
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (!empty($_POST['afzender']) && !empty($_POST['subject']) && !empty($_POST['inhoud']) && !empty($_POST['captcha']) )
{
echo $_POST['captcha'];
if ($captchafinal == $_POST['captcha'])
{
echo "<div class='approved'>Succesvol verstuurd.</div>";
}
}
else
{
echo "<div class='error'>Één of meer velden zijn niet correct ingevuld.</div>";
}
}
语句if ($captchafinal == $_POST['captcha'])
评估为false,但我不知道为什么。
答案 0 :(得分:1)
您可能遇到以下问题。你打电话给php脚本,选择随机5号码并将这5张图片显示给客户端。客户端键入他们看到的内容并再次调用php。 php AGAIN 选择5个随机数并将其与用户输入进行比较。但脚本不会比较显示给客户端的数字,而是新生成的集合。