所以我做了一個表單密碼系統,我遇到了這個問題,我嘗試輸入數組中的值,密碼仍然錯誤?(我將“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 關注
- 147 瀏覽
添加回答
舉報
0/150
提交
取消