Reputation: 5
Okay, so I am trying to make my own captcha system. I have two pages, the form page, and the form action. Here is my codes:
<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";
?>
and then the next:
<?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.
}
?>
How can I take the $captcha variable from the other form and put it onto the captcha.php page? I figured that $captcha has lots of variables put into one, so how
Upvotes: 0
Views: 175
Reputation: 5156
Use a session: http://php.net/manual/en/features.sessions.php
Generate a random string when the session is created and store it in $_SESSION
. Use that value to draw the CAPTCHA and to check it.
Upvotes: 1