如何在文本文件中保存用户名和密码?

时间:2018-03-11 19:58:54

标签: php html login passwords username

我知道这个问题是重复的,但是StackOverFlow和其他网站的所有问题都没有帮助我...所以我想在.txt文件中保存输入中的用户名和密码,但我拥有的一切尝试到目前为止没有工作。这是PHP代码:

<?php
if(isset($_POST['Submit-Button']))
    {
    $username = $_POST['Username'];
    $password = $_POST['Password'];
    $text = $username . "," . $password . "\n";
    $fp = fopen('accounts.txt', 'a+');

    if(fwrite($fp, $text))  {
        echo 'Saved';
    }
fclose ($fp);
header("Location: http://www.google.com");
die();
}?>

这是我的HTML:

<span>Username</span>
<input type="text" name="Username" id="Login-Input-Username">

<span>Password</span>
<input type="password" name="Password" id="Login-Input-Password">

<button type="submit" name="Submit-Button" value="submit" id="Login-
Button">Sign In</button>

因此,点击登录后,accounts.txt文件为空,我无法理解为什么它无效。

1 个答案:

答案 0 :(得分:1)

刚查看了您网页的来源,我认为您忘记在表单中添加“操作”和“方法”。

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

enter image description here