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

How to save Username and Password in a Text File?

我知道这个问题是重复的,但 Whosebug 和其他网站中的所有问题都没有帮助我...所以我想将输入的用户名和密码保存在 .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 文件在我点击登录后是空的,我不明白为什么它不起作用。

刚刚检查了您页面的来源,我想您忘记了将 "action" 和 "method" 添加到您的表单中。

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