dongshang6062 2015-09-04 17:57
浏览 9
已采纳

我需要提示让我的PHP密码工作

I have trouble with these codes:

password.php:

    <html>

 <head>

    <title>Password!</title>
    <meta charset="UTF-8">

 </head>

 <body>

    <ul>

    <form action="check.php" method="POST">

        <li><input type="password" name="no1" placeholder="enter your password"></li>
        <li><input type="submit" value="GO!"></li>

    </form>

    </ul>

 </body>

Here is password2.php:

    <html>

 <head>

    <title>Password!</title>
    <meta charset="UTF-8">

 </head>

 <body>

    <ul>

    <form action="check.php" method="POST">

        <li><input type="password" name="name" placeholder="verify your password"></li>
        <li><input type="submit" value="GO!"></li>

    </form>

    </ul>

 </body>

And here is check.php:

    <?php

$enter = $_POST['no1'];

if (empty($enter)) {
    echo "Please enter password!";
}

if (!(empty($enter))) {
    echo "Your password is $enter";
}


?>

<html>
<body>
<p><a href="password2.php">Move on!</a></p>
</body>
</html>

<?php

$check = $_POST['name'];

if ($check == $enter) {
    echo "Acces Granted";
}

if (!($check == $enter)) {
    echo "Acces denied!";
}

?>

The troubles I have are:

  • check.php doesn't recognise "name" from password2.php
  • And I can't verify the password
  • 写回答

1条回答 默认 最新

  • duanli9591 2015-09-04 18:29
    关注

    Because $_POST variable is not persistent between requests it would not work. You can store the value from first form in the $_SESSION variable and retrieve it from session.

    More info about php sessions here

    Leave everything as it is in your question except check.php, here is the modified one:

               <?php
    
                //starting the session in PHP
                session_start();
    
                $enter = null;
    
                // this is all the logic you need for retrieving `no1` from POST or SESSION 
                if (isset($_POST['no1'])){
                    $enter = $_POST['no1'];
                    $_SESSION['no1'] = $enter;
                }elseif(isset($_SESSION['no1'])){
                    $enter = $_SESSION['no1'];
                }
    
    
    
    
                if (empty($enter)) {
                    echo "Please enter password!";
                }
    
                if (!(empty($enter))) {
                    echo "Your password is $enter";
                }
    
    
                ?>
    
                    <html>
                    <body>
                    <p><a href="password2.php">Move on!</a></p>
                    </body>
                    </html>
    
                <?php
    
                $check = $_POST['name'];
    
                if ($check == $enter) {
                    echo "Acces Granted";
    
                    // you can comment the next line if you are debugging,
                    // but after that you should destroy de session so you don't have a password as plain text
                    session_destroy();
                }
    
                if (!($check == $enter)) {
                    echo "Acces denied!";
                }
    
                ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vscode的问题提问
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM