我正在构建一个小型的基于php的应用程序,它需要一个包含用户名和密码的“config.php”文件。而不是要求最终用户在将应用程序上传到服务器之前手动修改“config.php”,我想从设置表单动态生成“config.php”。如何通过PHP表单生成“config.php”?
基本上,我想用这个:
<form method="POST" action="?setup-config">
<fieldset>
<div class="clearfix">
<label for="username">Desired User Name</label>
<div class="input">
<input type="text" name="username" id="username">
</div>
</div>
<div class="clearfix">
<label for="password">Desired Password</label>
<div class="input">
<input type="password" name="password" id="password">
</div>
</div>
<div class="actions">
<input type="submit" value="Save Username & Password">
</div>
</fieldset>
</form>
打造 “config.php文件”:
<?php
$username = 'entered username';
$password = 'entered password';
使用['frwite()'](http://php.net/manual/en/function.fwrite.php) – 2012-08-03 17:19:46
什么?不,不,不,不,不。用户名和密码属于数据库。期。密码需要通过散列来保证。 – Matt 2012-08-03 17:20:12
@Matt - 我原则上同意,但在文件系统中为小应用程序存储用户登录数据没有任何问题,只要(a)在文档根目录之外;和(b)你散列密码数据(如你所提到的) – 2012-08-03 18:21:56