I want to create a simple captcha system with php . But I'm having some problems:
<?php
// init variables
$min_number = 15455551;
$max_number = 94577758;
// generating random numbers
$random_number1 = mt_rand($min_number, $max_number);
$random_number2 = mt_rand($min_number, $max_number);
?>
<form method="POST">
<p>
Resolve the simple captcha below: <br />
<?php
echo $random_number1 . ' + ' . $random_number2 . ' = ';
?>
<input name="captchaResult" type="text" size="2" />
<input name="firstNumber" type="hidden" value="<?php echo $random_number1; ?>" />
<input name="secondNumber" type="hidden" value="<?php echo $random_number2; ?>" />
</p>
<p>
<input type="submit" value="submit" />
</p>
</form>
<?php
$captchaResult = $_POST["captchaResult"];
$firstNumber = $_POST["firstNumber"];
$secondNumber = $_POST["secondNumber"];
$checkTotal = $firstNumber + $secondNumber;
if ($captchaResult == $checkTotal) {
echo '<input id="btn" type="submit" value="Get" />';
} else {
echo '<h2 class="red">Wrong Captcha. Try Again</h2>';
}
?>
It echo the 'Get' button without submitting captcha . It's the code problem . And I want to create a
<a href="code.php">Get Code</a>
button,
user need go this page and then they get a code for it.
I delete the code from index.php
Resolve the simple captcha below: <br />
<?php
echo $random_number1 . ' + ' . $random_number2 . ' = ';
?>
And add a code on code.php something like this
<?php
$result= $random_number1 + $random_number2;
echo "$result";
?>
but how can I call the code which is already generated in index.php by user .