Hi, I wanted to know how I could make this code, when logging in, compare if the credentials are correct by comparing the values of an array. I did it with a foreach, comparing them with if, but the result that gives me is that everyone can enter.
<?php
$usuarios = array (
"juan@juan" => "juan",
"[email protected]" => "pedro",
"[email protected]" => "maria"
);
if($_POST)
{
if (isset($_POST["email"]))
$email = $_POST["email"];
else $usuario = "";
if (isset($_POST["contrasena"]))
$contrasena = $_POST["contrasena"];
else $contrasena = "";
if($email != "" && $contrasena != "")
{
foreach ($usuarios as $emails => $contrasenas)
{
if ($email = $emails && $contrasena = $contrasenas)
{
$_SESSION["email"] = $email;
header ("Location: contenido.php");
break;
}
else
{
header ("Location: registro.php");
echo "Introduce email y contraseña correctos";
}
}
}
else
{
header ("Location: registro.php");
echo "Introduce email y contraseña correctos";
}
}
?>