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

PHP 请求未验证密码是否正确,然后继续打开 HTML 按钮

PHP 请求未验证密码是否正确,然后继续打开 HTML 按钮

PHP
天涯尽头无女友 2022-08-19 16:56:44
我不知道在这里做什么。PHP post请求(request.php)只是在单击按钮(correct.html)后继续下一页,即使我没有在输入中键入任何内容。我希望它验证密码是否正确,如果是这样=继续更正.html,否则提醒用户。PHP 代码:<?php $pass = $_POST['password'];if ($pass == "password"){   include "correct.html";}else{   echo "Password incorrect";}?>代码:<div class="input-container">    <input class="input-field" type="password" placeholder="Your passphrase" /><br>    <i class="fa fa-user icon"></i></div><br><div id=continue>    <form action="request.php" method="post">     <button class="button" name="password" value="password" style="vertical-align:middle"><span>Confirm</span></button>    </form></div>
查看完整描述

3 回答

?
潇湘沐

TA贡献1816条经验 获得超6个赞

您应该首先为输入类型密码或按钮添加名称属性值,如下所示


<div id=continue>

        <form action="request.php" method="post">

            <input class="input-field" type="password" name="password" placeholder="Your passphrase" />

            <button class="button" name="submit" value="submit" style="vertical-align:middle"><span>Confirm</span></button>

        </form>

</div>

之后你的php代码应该是这样的


    <?php


    if(isset($_POST['submit']))

    {

    $pass = $_POST['password'];


    if ($pass == "password")

    {

       include "correct.html";

    }


    else

    {

       echo "Password incorrect";

    }

    }

?>


查看完整回答
反对 回复 2022-08-19
?
小怪兽爱吃肉

TA贡献1852条经验 获得超1个赞

这是你必须具备的:form


<div id=continue>

    <form action="request.php" method="post">

        <!-- Note that input and button are under the SAME <form> -->

        <input class="input-field" type="password" name="password" placeholder="Your passphrase" />

        <!-- Note `name` attributes of `button` and `input`  -->

        <button class="button" name="button" value="submit" style="vertical-align:middle"><span>Confirm</span></button>

    </form>

</div>

在服务器上:


<?php


// for debugging purposes, remove when you want

print_r($_POST);


// as 'password' is now NAME of INPUT, `$pass` stores the value from the INPUT

$pass = $_POST['password'];


if ($pass == "password")

{

   include "correct.html";

}


else

{

   echo "Password incorrect";

}


查看完整回答
反对 回复 2022-08-19
?
慕尼黑的夜晚无繁华

TA贡献1864条经验 获得超6个赞

您应该阅读有关 PHP 中的表单提交的信息。在此特定实例中,您的表单未作为按钮需要提交属性提交提交,即 .<button type="submit"

此外,要调试 post 数据,可以使用 。var_dump($_POST); die();


查看完整回答
反对 回复 2022-08-19
  • 3 回答
  • 0 关注
  • 104 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信