SaeDEV2.2/php/connexion.php
2024-06-15 17:47:50 +02:00

99 lines
2.6 KiB
PHP

<html lang="fr" >
<head>
<meta charset="utf-8">
<link rel="icon" href="../img/jo2024.jpg" >
<link rel="stylesheet" href="../css/style.css">
<title>Connexion - Jeux Olympiques</title>
</head>
<body>
<?php
// Informations de connexion à la base de données
require_once 'common.php';
session_start();
if (!empty($_POST['login']) && !empty($_POST['password'])) {
$db = initDatabase();
$login = $_POST['login'];
$password = $_POST['password'];
$result=mysqli_query($db,"SELECT * FROM user WHERE login = '$login' ");
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
$hash = $row['mdp'];
$mail = $row['mail'];
$nom = $row['nom'];
$prenom = $row['prenom'];
$genre = $row['genre'];
$role = $row ['Role'];
if (password_verify($password, $hash)) {
if ($login) {
$_SESSION['login'] = $login;
$_SESSION['mail'] = $mail;
$_SESSION['nom'] = $nom;
$_SESSION['prenom'] = $prenom;
$_SESSION['genre'] = $genre;
$_SESSION['role'] = $role;
header('Location: ../index.php');
exit();
}
} else {
$error_verif2 = "Mot de passe incorrect";
}
} else {
$error_verif = "Ce login n'existe pas";
}
}
// Récupération des données du formulaire
?>
<header>
<h1 class='Hello'> Page de connexion </h1>
<nav>
<a href="../" class="categorie">Page d'accueil</a>
</nav>
</header>
<div class="connexion">
<u><i><h2>Connexion</h2></i></u><br>
<form action="" method="post">
<label for="login">Login :</label><br>
<input type="text" id="login" name="login" required value="<?php if (isset($_REQUEST['login'])) { echo $_REQUEST['login']; } ?>"><br>
<?php if (isset($error_verif)) {echo "<div class='error-message'>$error_verif</div>";} ?>
<br><br><label for="password">Mot de passe :</label><br>
<input type="password" id="password" name="password" required placeholder="••••••••" value="<?php if (isset($_REQUEST['password'])) { echo $_REQUEST['password']; } ?>"><br>
<?php if (isset($error_verif2)) {echo "<div class='error-message'>$error_verif2</div>";} ?>
<br><br><button type="submit" class="submit">Se connecter </button>
</form>
<p class="compteUser">Vous ne possédez pas de compte ? <br><a href="inscription.php">Inscrivez-vous !</a></p>
</div>
<footer>
<?php require_once('footer.php'); ?>
</footer>
</body>
</html>