-1

快速提问。我为家族企业设置了考勤卡和采购订单系统。员工输入用户名和密码进入系统。每次家庭雇用某人时,他们都会向我发送信息。我使用 htpasswd 生成器,然后打开文件,添加它,然后使用 ftp 重新上传。我的妻子使用我设置的 php 页面将他们的信息输入到数据库中,我想知道是否有办法允许她使用 txt 字段,她可以将生成的 pw 复制并传递到 htpasswd 文件中。无需我总是改变它。

总结一下:是否有一个表单命令,当我输入 txt 字段并推送它时,它会自动将 txt 放入 htpasswd 文件中

4

1 回答 1

2

您需要创建一个 php 页面。这个答案有一个你需要的代码示例:

$username = $_POST['user'];
$password = $_POST['pass'];
$new_username = $_POST['newuser'];
$new_password = $_POST['newpass'];
$action = $_POST['action'];
//read the file into an array
$lines = explode("\n", file_get_contents('.htpasswd'));

//read the array and change the data if found
$new_file = "";
foreach($lines as $line)
{
    $line = preg_replace('/\s+/','',$line); // remove spaces
    if ($line) {
        list($user, $pass) = split(":", $line, 2);
        if ($user == $username) {
            if ($action == "password") {
                $new_file .= $user.':'.$new_password."\n";
            } else {
                $new_file .= $new_username.':'.$pass."\n";
            }
        } else {
            $new_file .= $user.':'.$pass."\n";
        }
    }
}

//save the information
$f=fopen(".htpasswd","w") or die("couldn't open the file");
fwrite($f,$new_file);
fclose($f);

这里还有一个稍微完整的解决方案或者只是在谷歌上查找。

于 2013-11-06T04:35:57.103 回答