为了账号安全,请及时绑定邮箱和手机立即绑定

如何使变量具有多个值,并使这些值在输入标签中有效?

如何使变量具有多个值,并使这些值在输入标签中有效?

PHP
RISEBY 2023-03-04 17:58:12
所以我做了一个表单密码系统,我遇到了这个问题,我尝试输入数组中的值,密码仍然错误?(我将“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.

}


查看完整回答
反对 回复 2023-03-04
  • 1 回答
  • 0 关注
  • 184 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号