SaeDEV2.2/php/connexion.php

75 lines
1.8 KiB
PHP
Raw Normal View History

2024-06-10 19:29:21 +02:00
<?php
// Informations de connexion à la base de données
2024-06-11 11:27:58 +02:00
require_once 'common.php';
session_start();
if (!empty($_REQUEST['login']) && !empty($_REQUEST['password'])) {
$db = initDatabase();
$login = $_POST['login'];
$password = $_POST['password'];
2024-06-10 19:29:21 +02:00
2024-06-11 11:27:58 +02:00
$result=mysqli_query($db,"SELECT * FROM user WHERE login = '$login' ");
2024-06-10 19:29:21 +02:00
2024-06-11 11:27:58 +02:00
if (mysqli_num_rows($result) > 0) {
2024-06-10 19:29:21 +02:00
2024-06-11 11:27:58 +02:00
$row = mysqli_fetch_assoc($result);
$hash = $row['mdp'];
2024-06-10 19:29:21 +02:00
2024-06-11 11:27:58 +02:00
if (password_verify($password, $hash)) {
if ($login) {
$_SESSION['login'] = $login;
header('Location: ../index.php');
2024-06-11 11:27:58 +02:00
exit();
}
2024-06-10 19:29:21 +02:00
2024-06-11 11:27:58 +02:00
} else {
echo "Échec de la connexion : couple login/mot de passe invalide.";
}
2024-06-10 19:29:21 +02:00
} else {
echo "Échec de la connexion : login inconnu.";
2024-06-10 19:29:21 +02:00
}
2024-06-11 11:27:58 +02:00
}
// Récupération des données du formulaire
?>
<html lang="fr">
2024-06-11 11:27:58 +02:00
<head>
<meta charset="utf-8">
<link rel="icon" href="../img/jo2024.jpg" >
2024-06-11 11:27:58 +02:00
<link rel="stylesheet" href="../css/style.css">
<title>Connexion - Jeux Olympiques</title>
2024-06-11 11:27:58 +02:00
</head>
2024-06-11 11:27:58 +02:00
<body>
<div id="content_cours">
<header>
<nav>
<a href="../index.php" class="categorie">Page d'accueil</a>
2024-06-11 11:27:58 +02:00
</nav>
</header>
<h2>Connexion</h2><br>
2024-06-11 11:27:58 +02:00
<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>
2024-06-11 11:27:58 +02:00
<label for="password">Mot de passe :</label><br>
<input type="password" id="password" name="password" required placeholder="••••••••" value="<?php if (isset($_REQUEST['login'])) { echo $_REQUEST['login']; } ?>"><br>
2024-06-11 11:27:58 +02:00
<input type="submit" value="Se connecter">
</form>
2024-06-10 19:29:21 +02:00
2024-06-11 11:27:58 +02:00
</body>
</html>