0

さて、私は独自のキャプチャシステムを作ろうとしています。フォーム ページとフォーム アクションの 2 つのページがあります。これが私のコードです:

<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 には多くの変数が 1 つにまとめられていると考えました。

4

1 に答える 1

1

セッションを使用してください: http://php.net/manual/en/features.sessions.php

セッションの作成時にランダムな文字列を生成し、 に保存し$_SESSIONます。その値を使用して CAPTCHA を描画し、確認します。

于 2012-08-29T00:02:11.490 に答える