Why is the verification code created by the random function always one step different from the verification code entered in the form, and the two values ​​are inconsistent no matter how I enter them? ? ?
xiao~莫
xiao~莫 2019-04-22 20:33:59
0
0
789

<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>



xiao~莫
xiao~莫

reply all(0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!