更新时间:2023-01-23 13:41:18
可以说您的文本文件看起来像这样:
Lets say your text file looks something like this:
pete|petepass|pete@somesite.com|Pete Enterprizes
john|johnpass|john@somedomain.com|John Corporation
您的代码可以读取如下内容:
Your code can read something like this:
$userN = $_POST['user-name'];
$passW = $_POST['pass-word'];
$userlist = file ('users.txt');
$email = "";
$company = "";
$success = false;
foreach ($userlist as $user) {
$user_details = explode('|', $user);
if ($user_details[0] == $userN && $user_details[1] == $passW) {
$success = true;
$email = $user_details[2];
$company = $user_details[3];
break;
}
}
if ($success) {
echo "<br> Hi $userN you have been logged in. <br>";
} else {
echo "<br> You have entered the wrong username or password. Please try again. <br>";
}