我刚开始学习php,在我的第一个程序中,我想做一个基本的php网站,具有登录功能,用户和密码数组。
我的想法是将用户名存储为列表参数,并将passwd作为内容,如下所示:
arr = array(username => passwd, user => passwd);
现在我的问题是,我不知道如何从文件(data.txt
)中读取,以便将其添加到数组中。
data.txt sample:
username passwd
anotherUSer passwd
我已经用fopen
打开了这个文件,并将其存储在$data
中。
5条答案
按热度按时间4nkexdtk1#
可以使用
file()
函数。yebdmbv42#
修改这个PHP示例(取自官方PHP站点... * 总是 * 检查第一!):
致:
请注意,您不应该将登录详细信息存储在未加密的文本文件中,这种方法存在严重的安全问题。我知道你是PHP新手,但最好的方法是将其存储在DB中,并使用MD5或SHA1等算法加密密码,
pxy2qtax3#
您不应该将敏感信息存储为明文,但为了回答您的问题,
Take a look at this thread.
bfrts1fy4#
这也适用于非常大的文件:
t30tvxxf5#
使用file()或file_get_contents()创建数组或字符串。
根据需要处理文件内容