【发布时间】:2019-06-24 06:37:17
【问题描述】:
我正在制作一个比较两个变量的验证页面
第一个是之前从 python 脚本生成的随机代码,并将结果带到名称为 $code 输出示例 (8063D0A7) 下的 php 变量,它是 8 个数字和字母字符
第二个是用户输入($verf)
当用户点击提交时,($code) 和($verf) 应该进行比较,如果为真则转移到其他页面,如果不是则显示重试
我尝试了很多方法,但在任何情况下它总是显示错误,任何输入
<?php
session_start(); ///starts a session and getting the variables from another page
echo "E-mail has been sent to " ;
echo $_SESSION['email']; ///gets $email from another page
echo $email , " ";
echo $_SESSION['code']; ///gets the $code from another page
$email = escapeshellarg($_SESSION['email']); ///make an arg to put in bash script
$code = escapeshellarg($_SESSION['code']);
$addr = shell_exec("./test.sh $email $code"); ///execute bash script to send $code to $email
?>
<!DOCTYPE HTML>
<html>
<body>
<h2>E-mail Verfication</h2>
<form method="post" action="">
Name: <input type="string" name="verf" value="">
<br><br>
<input type="submit" name="submit2" value="Submit">
</form>
<?php
if (isset($_POST['submit2'])) {
$verf = $_POST['verf'];
if ($verf == $code) {
echo "Correct!";
header('Location: 12.php');
} else {
echo "Wrong!";
}
} else {
echo "please fill the verification";
}
echo $verf;
echo $code;
?>
</body>
</html>
我认为识别变量存在问题,例如将 $code 作为字符串,将 $verf 作为其他类型的输入,所以它总是错误的,我不知道我是 php 新手帮助 PLZ .. :D
【问题讨论】:
标签: php string if-statement compare