PHP rand()函数

时间:2013-07-05 23:18:28

标签: php random

我想制作类似反垃圾邮件系统的东西,我有这个HTML:

What is <?php echo $six; ?> + <?php echo $rand1; ?> <input type="text" name="human" id="human">

对于这些变量:

$human = @$_POST['human'];
$rand1 = rand(1, 9);
$six = 6; 
$res = $rand1 + $six;

然后我这样做:

if($human==$res){
  echo "Correct";
}else{
  echo "Incorrect";
}

这不起作用!有什么想法吗?

1 个答案:

答案 0 :(得分:0)

请记住通过html表单提供$ res或$ rand1变量值 - 将php更改为以下内容:

$human = @$_POST['human'];
$res = @$_POST['res'];

if($human==$res){
  echo "Correct";
}else{
  echo "Incorrect";
}

$rand1 = rand(1, 9);
$six = 6; 
$res = $rand1 + $six;

然后添加:

<input type="hidden" name="res" value="<php echo $res;?>">

进入你的html表单

相关问题