我是新來學習PHP和我的第一個程序之一,我想做一個基本的PHP網站與登錄功能與陣列的用戶和passwd。如何從php中的文件讀取每行?
我的想法是存儲用戶名作爲參數列表,並有passwd作爲內容,就像這樣:
arr = array(username => passwd, user => passwd);
我現在的問題是,我不知道我怎樣才能從文件中讀取(data.txt
),所以我可以將它添加到數組中。
data.txt sample:
username passwd
anotherUSer passwd
我已經打開了文件,fopen
並將其存儲在$data
。
你不應該存儲敏感信息以明文形式。 – Norse
在@Norse的建議之上,這可以很容易地搜索到。 'file_get_contents'和'split'會爲你做。 – Qix
@Norse我知道我不應該以純文本存儲任何敏感信息,但這是我第一個真正的PHP程序,它只是爲了學習,我沒有看到讓它變得太複雜的觀點。我當然會添加一個加密,如果這將是一個真正的網站有一天。 – Alvar