Я пытаюсь создать простую страницу входа,
, если я беру следующий вариант массива, он работает:
$users = [['hello@domain.de' => 'Asd23'], ['hello2@domain.de' => 'hell5123']];
if (isset($logins[$userKey][$email]) && $logins[$userKey][$email] == $password)
, но с следующий вариант многомерного ассоциативного массива. Я не могу этого сделать.
Что я делаю или я неправильно понял?
// Multidimensional Associative Array
$users = [
////////////
[
'email' => 'sandra@domain.com',
'password' => 'San1',
'name' => 'Sandra',
'lastname' => 'Meier',
'status' => 'Admin',
'content' => ''
],
[
'email' => 'franz@domain.com',
'password' => 'Fra1',
'name' => 'Franz',
'lastname' => 'Eder',
'status' => 'Standard',
'content' => 'leer'
],
]
// check and assign submitted email and password to new variable
$email = isset($_POST['email']) ? $_POST['email'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
if(isset($_POST['Submit'])) {
// find the key from the given email
// Multidimensional Array Searching (Find key by specific value)
$userKey = array_search($email, array_column($users, 'email'));
// check if the given email address and password exist and match
if (isset($users[$userKey][$email]) && $users[$userKey][$password] == $password) {
// success: email address and password exist and the email address matches the password
// set session variables and redirect to protected page
$_SESSION['UserData']['email'] = $users[$userKey][$email];
header("location:{$protocol_domain}{$actualURl}");
exit;
} else {
// unsuccessful attempt: email address and password do not exist or the emails do not match
// Set error message
$msg = '<span style="color:red">Invalid Login Details</span>';
}
}