我正在構建一個小型的基於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