<form action="" method="post">
<p>Please enter the verification code:<input type='text' name='v1'>
<?php
session_start(); //Start session
$input = array_merge(range('a', 'z'),range('A', ' Z'),range('0', '9')); //Create a verification code array
shuffle($input); //Shuffle the array
$result = '' ; //Verification code result initialization
for ($i=0; $i < 4; $i ) { //Loop out the first four digits of the verification code
$result .= $ input[$i]; //Assign verification code through loop
}
echo $result; //Output verification code
$_SESSION['Result'] = $ result; //Assign the result of the verification code to session
// setcookie(session_name(),session_id(),time() 30);
if (isset($_REQUEST[' v1'])) { //Judge whether the input box has a value
if (strtoupper($_REQUEST['v1']) == strtoupper($_SESSION['Result'])) { //Judge verification The code is correct
echo "<script>alert('Verification input is correct, login successful!!')</script>";
unset($_SESSION['Result' ]);
}else{
echo "<br/>Verification input error, please re-enter!!<br/>";
echo "The value of the random function is:".$_SESSION['Result']."<br/>";
echo 'The value of the form input is:'.$_REQUEST['v1'] ;
}
}
?>
</p>
<input type="submit" value ="Confirm login"> <!--Submit the value of the input box-->
</form>