This commit is contained in:
2025-10-29 16:54:38 +01:00
parent 7181ead64e
commit 62cf15ab8b
4 changed files with 168 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
if ( !isset($_GET['id']) || !ctype_digit($_GET['id']) ) {
die("Erreur 404 : L'article demandé est introuvable.");
}
$id_article = $_GET['id'];
require_once 'php/pdo.php';
$sql = "SELECT * FROM articles WHERE id = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$id_article]);
$article = $stmt->fetch(PDO::FETCH_ASSOC);
if ($article === false) {
die("Erreur 404 : L'article demandé est introuvable.");
}
?>
<!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<meta charset="UTF-8">
<title><?php print htmlspecialchars($article['titre']); ?></title>
</head>
<body>
<a href="index.php">← Retour à l'accueil</a>
<hr>
<article>
<h1><?php print htmlspecialchars($article['titre']); ?></h1>
<p>
<em>Publié le : <?php print $article['date_creation']; ?></em>
</p>
<div>
<?php
print nl2br(htmlspecialchars($article['contenu']));
?>
</div>
</article>
</body>
</html>

40
dashboard.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
$user_login = $_SESSION['user_login'];
?>
<!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Tableau de Bord - Admin</title>
</head>
<body>
<header>
<h1>Tableau de Bord</h1>
<p>Bienvenue, <?php echo htmlspecialchars($user_login); ?> ! (ID: <?php echo $_SESSION['user_id']; ?>)</p>
<nav>
<a href="logout.php">Se déconnecter</a>
</nav>
</header>
<hr>
<main>
<h2>Gestion des articles</h2>
<p>C'est ici que vous pourrez bientôt gérer vos articles.</p>
<ul>
<li><a href="creer_article.php">Ajouter un nouvel article</a></li>
</ul>
</main>
</body>
</html>

71
login.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
session_start();
if (isset($_SESSION['user_id'])) {
header('Location: dashboard.php');
exit;
}
require_once 'php/pdo.php';
$erreur_message = "";
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (empty($_POST['login']) || empty($_POST['password'])) {
$erreur_message = "Veuillez remplir le login et le mot de passe.";
} else {
$login_saisi = $_POST['login'];
$password_saisi = $_POST['password'];
$sql = "SELECT * FROM utilisateur WHERE login = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$login_saisi]);
$utilisateur = $stmt->fetch(PDO::FETCH_ASSOC);
if ($utilisateur && password_verify($password_saisi, $utilisateur['password'])) {
$_SESSION['user_id'] = $utilisateur['id'];
$_SESSION['user_login'] = $utilisateur['login'];
header('Location: dashboard.php');
exit;
} else {
$erreur_message = "Login ou mot de passe incorrect.";
}
}
}
?>
<!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Connexion - Admin</title>
</head>
<body>
<h1>Zone Admin</h1>
<?php
if (!empty($erreur_message)) :
?>
<?php print $erreur_message; ?>
<?php endif; ?>
<form action="login.php" method="POST">
<div>
<label for="login">Login :</label>
<input type="text" id="login" name="login">
</div>
<div>
<label for="password">Mot de passe :</label>
<input type="password" id="password" name="password">
</div>
<div>
<button type="submit">Se connecter</button>
</div>
</form>
</body>
</html>

8
logout.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
session_start();
session_destroy();
header('Location: login.php');
exit;
?>