所以我做了一个表单密码系统,我遇到了这个问题,我尝试输入数组中的值,密码仍然错误?(我将“batanes”或“Batanes”放入输入并提交,但由于某种原因它不是正确的密码。即使它是数组中的确切值)<form id="pass" method="POST"> <b><label for="Pass"> Where is our Ultimate Travel Destination Wish List in the Philippines? </label></b> <input id="Pass" name="Pass" type="text" placeholder="Enter Password Here..." required> <input type=submit> <?php error_reporting(0); $pass= array("Batanes", "batanes"); $enter= $_POST['Pass']; if ($enter === $pass) { echo <<<EOL $('<div class=overlay></div>').bind('mouseover',function(){ }); $(<div class="popup"> Good Job Man! <br> Now to the next! </div>).bind('mouseout', function(){ }); <script> setTimeout(function(){ window.location.href = 'mommysthirdimahe.html'; }, 2000); </script> EOL; exit; } elseif ($enter === NULL) { echo ""; }我如何做到这一点,以便当 $enter 等于 $pass 数组中的值时,它执行“if”中的函数?
1 回答

慕神8447489
TA贡献1780条经验 获得超1个赞
该问题的答案是in_array函数。
例子:
if (in_array($enter, $pass)) {
// execute whatever you want
}
我注意到您在数组中存储了两次“Batanes”字样$pass
,以处理区分大小写的检查。取而代之的是,您可以仅存储小写版本并使用strtolower函数将输入也转换为小写。
例子:
$pass = ['batanes'];
if (in_array(strtolower($enter), $pass)) {
// execute whatever you want
}
但是在这种情况下,您不再需要数组,您可以简单地使用它:
if ($pass === $enter) {
// execute whatever you want.
}
- 1 回答
- 0 关注
- 184 浏览
添加回答
举报
0/150
提交
取消