tdphp/td5/connexion_traitement.php

22 lines
560 B
PHP
Raw Normal View History

2023-03-22 08:13:04 +01:00
<?php
if (isset($_POST["valide"])) {
$identifiant = $_POST["identifiant"];
$password = $_POST["password"];
$users = json_decode(file_get_contents("users.json"), true);
$user = null;
foreach ($users as $u) {
if ($u["username"] == $identifiant && $u["password"] == $password) {
$user = $u;
break;
}
}
if ($user == null) {
header("Location: connexion.php?error=1");
} else {
session_start();
$_SESSION["user"] = $user;
header("Location: index.php");
}
}