PHP验证码系统

PHP验证码系统,php,Php,好的,我正在尝试制作我自己的验证码系统。我有两个页面,表单页面和表单操作。这是我的密码: <html> <head> <title>Captcha</title> <center> <form method="POST" action="captcha.php"> <label>Entered Text: </label><input type="text" name="captcha">

好的,我正在尝试制作我自己的验证码系统。我有两个页面,表单页面和表单操作。这是我的密码:

<html>
<head>
<title>Captcha</title>
<center>
<form method="POST" action="captcha.php">
<label>Entered Text:  </label><input type="text" name="captcha">
<input type="submit" name="submit" value="Submit Captcha!">
</form>
</center>
</head>
</html>
<?php
$firstdigit = rand(1, 9);
$seconddigit = rand(27, 105);
$lastdigit = rand(1050, 9515);
$middle = rand(1000, 20000);
$captcha = "<b><center><font face=\"Arial\">AX-$firstdigit-X-$seconddigit-K3I$middle-AN3Z-$lastdigit</font></center></b>";
echo "$captcha";
?>

验证码
输入的文本:
然后是下一个:

<?php
$captcha2 = $_POST['captcha']; //This is the input field
$submit = $_POST['submit'];  //This is Submit
if ($submit) {
  if ($captcha2) {
    echo "Everything is good."; //Echo'd if everything is good
   } else {
  echo "Please fill in all fields."; //Echo'd if $captcha isn't filled out
   }
 } else {
echo "Direct access not allowed.  Please click submit.";   //Echo'd if  submit is not pressed, and they access this directly.
}
?>

如何从另一个表单获取$captcha变量并将其放到captcha.php页面上?我想$captcha有很多变量放在一个里面,所以如何使用会话:


创建会话时生成一个随机字符串,并将其存储在
$\u session
中。使用该值绘制验证码并进行检查。

必须在所有使用$\u会话变量的脚本上使用
session\u start()